StopWatch - Client

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:4分
  • The StopWatch API provides methods to measure the duration of operations.

    You can use this API in client-side scripts using ListV2 and ListV3 APIs.

    StopWatch - StopWatch()

    Creates an instance of the StopWatch class.

    Uses the current time as the start time.

    表 : 1. Parameters
    Name Type Description
    None
    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(Date initialDate)

    Creates an instance of the StopWatch class using the specified date as the initial value.

    表 : 2. Parameters
    Name Type Description
    initialDate Date The initial date for the object.

    StopWatch - getTime()

    Returns the number of milliseconds since the timer started.

    表 : 3. Parameters
    Name Type Description
    None
    表 : 4. Returns
    Type Description
    Number Time since the timer started.

    Unit: Milliseconds

    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()

    Resets the timer start to the current time.

    表 : 5. Parameters
    Name Type Description
    None
    表 : 6. Returns
    Type Description
    void
    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()

    Returns the elapsed time.

    表 : 7. Parameters
    Name Type Description
    None
    表 : 8. Returns
    Type Description
    String Elapsed time.

    Format: 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();