@26area/stop-watch 中文文档教程
Simple Stop Watch
这是通过打字稿测量性能的简单秒表。
只是,
import {StopWatch} from '@26area/stop-watch';
import {Duration} from '@26area/stop-watch';
import {sleep} from '@26area/stop-watch';
const stopWatch: StopWatch = StopWatch.start();
await sleep(1000);
const duration: Duration<undefined> = stopWatch.stop();
const durationInMillies: number = duration.getByMillis();
// durationInMillies is 1000
我们还可以测量功能。
import {StopWatch} from '@26area/stop-watch';
import {Duration} from '@26area/stop-watch';
function foo(): number {
return 1;
}
async function fooAsync(): Promise<number> {
return 1;
}
const duration: Duration<number> = StopWatch.measure(() => foo());
duration.value;
// value is 1
const asyncDuration: Duration<number> = await StopWatch.measureAsync(() => fooAsync());
asyncDuration.value;
// value is 1
Simple Stop Watch
This is simple stop watch to measure performance by typescript.
Just,
import {StopWatch} from '@26area/stop-watch';
import {Duration} from '@26area/stop-watch';
import {sleep} from '@26area/stop-watch';
const stopWatch: StopWatch = StopWatch.start();
await sleep(1000);
const duration: Duration<undefined> = stopWatch.stop();
const durationInMillies: number = duration.getByMillis();
// durationInMillies is 1000
We can also measure function.
import {StopWatch} from '@26area/stop-watch';
import {Duration} from '@26area/stop-watch';
function foo(): number {
return 1;
}
async function fooAsync(): Promise<number> {
return 1;
}
const duration: Duration<number> = StopWatch.measure(() => foo());
duration.value;
// value is 1
const asyncDuration: Duration<number> = await StopWatch.measureAsync(() => fooAsync());
asyncDuration.value;
// value is 1