@26area/stop-watch 中文文档教程

发布于 5年前 浏览 39 项目主页 更新于 3年前

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
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文