StopWatch - クライアント

  • リリースバージョン: Washingtondc
  • 更新日 2024年02月01日
  • 読む3読むのに数分
  • StopWatch API には、操作の期間を測定するメソッドが用意されています。

    この API は、ListV2 および ListV3 API を使用してクライアント側スクリプトで使用できます

    StopWatch - StopWatch()

    StopWatch クラスのインスタンスを作成します。

    現在の時刻を開始時間として使用します。

    表 : 1. パラメーター
    名前 タイプ 説明
    なし
    var sw = new StopWatch();
    
    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }
    
    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");
    
    sw.restart();
    
    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }
    
    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();

    StopWatch - StopWatch(日付 initialDate)

    指定された日付を初期値に使用して、StopWatch クラスのインスタンスを作成します。

    表 : 2. パラメーター
    名前 タイプ 説明
    initialDate 日付 オブジェクトの初期日付。

    StopWatch - getTime()

    タイマーが開始されてからの時間をミリ秒単位で返します。

    表 : 3. パラメーター
    名前 タイプ 説明
    なし
    表 : 4. 返される内容
    タイプ 説明
    番号 タイマーが開始されてからの経過時間。

    単位:ミリ秒

    var sw = new StopWatch();
    
    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }
    
    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");
    
    sw.restart();
    
    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }
    
    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();

    StopWatch - restart()

    タイマー開始を現在の時刻にリセットします。

    表 : 5. パラメーター
    名前 タイプ 説明
    なし
    表 : 6. 返される内容
    タイプ 説明
    なし
    var sw = new StopWatch();
    
    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }
    
    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");
    
    sw.restart();
    
    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }
    
    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();

    StopWatch - toString()

    経過時間を返します。

    表 : 7. パラメーター
    名前 タイプ 説明
    なし
    表 : 8. 返される内容
    タイプ 説明
    文字列 経過時間。

    形式:HH:MM:SS。Sss

    var sw = new StopWatch();
    
    // some slow code here
    for(var i=0,j=1;i<100000000;i++) {
        j=Math.sqrt(i*i*j);
    }
    
    if (sw.getTime() > 500)
        console.log("Long running script. Execution time: [" + sw.toString() + "]");
    
    sw.restart();
    
    // some faster code
    for(i=0,j;i<100000;i++) {
        j= i + Math.random() * i;
    }
    
    console.log("Finished in: " + sw.getTime() + "ms");
    sw.stop();