StopWatch - クライアント
StopWatch API には、操作の期間を測定するメソッドが用意されています。
この API は、 ListV2 および ListV3 API を使用して、クライアント側スクリプトで使用できます。
StopWatch - StopWatch()
StopWatch クラスのインスタンスを作成します。
現在の時刻を開始時間として使用します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
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 クラスのインスタンスを作成します。
| 名前 | タイプ | 説明 |
|---|---|---|
| initialDate | 日付 | オブジェクトの初期日付。 |
StopWatch - getTime()
タイマーが開始されてからの時間をミリ秒単位で返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| [Number (番号)] | タイマーが開始されてからの経過時間。 単位:ミリ秒 |
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()
タイマーの開始を現在の時刻にリセットします。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| なし |
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()
経過時間を返します。
| 名前 | タイプ | 説明 |
|---|---|---|
| なし |
| タイプ | 説明 |
|---|---|
| 文字列 | 経過時間。 形式:HH:MM:SSSSS |
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();