---
sourceDocument: Xanadu API リファレンス
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - ja-JP

ft:publication_title :

    - Xanadu API リファレンス

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# StopWatch - クライアント

# StopWatch - クライアント {#ariaid-title1}

* リリースバージョン: Xanadu
* 
* 更新日 2024年08月01日
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：3分

StopWatch API には、操作の期間を測定するメソッドが用意されています。

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

## StopWatch - StopWatch() {#ariaid-title2}

StopWatch クラスのインスタンスを作成します。
現在の時刻を開始時間として使用します。
{#r_STPW-StopWatch__table_ylm_zl5_lv__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 1. パラメーター]

{#r_STPW-StopWatch__table_ylm_zl5_lv}  

    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) {#ariaid-title3}

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

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

{#r_STPW-StopWatch_D__table_vrh_11h_qv}

## StopWatch - getTime() {#ariaid-title4}

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

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 3. パラメーター]

{#r_STPW-getTime__table_vx2_sm5_lv} {#r_STPW-getTime__table_wx2_sm5_lv__entry__2}

| タイプ | 説明 |
|-|-|
| 番号 | タイマーが開始してからの経過時間。 単位：ミリ秒 |
[表 : 4. 返される内容]

{#r_STPW-getTime__table_wx2_sm5_lv}  

    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() {#ariaid-title5}

タイマーの開始を現在の時刻にリセットします。
{#r_STPW-restart__table_mkb_fn5_lv__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 5. パラメーター]

{#r_STPW-restart__table_mkb_fn5_lv} {#r_STPW-restart__table_nkb_fn5_lv__entry__2}

| タイプ | 説明 |
|-|-|
| なし |   |
[表 : 6. 返される内容]

{#r_STPW-restart__table_nkb_fn5_lv}  

    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() {#ariaid-title6}

経過時間を返します。
{#r_STPW-toString__table_xcm_pn5_lv__entry__3}

| 名前 | タイプ | 説明 |
|-|-|-|
| なし |   |   |
[表 : 7. パラメーター]

{#r_STPW-toString__table_xcm_pn5_lv} {#r_STPW-toString__table_ycm_pn5_lv__entry__2}

| タイプ | 説明 |
|-|-|
| 文字列 | 経過時間。 形式:HH:MM:SS。SSSの |
[表 : 8. 返される内容]

{#r_STPW-toString__table_ycm_pn5_lv}  

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


