mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 01:29:14 -05:00
02865cb5a2
Closes #17589. ```ts Deno.bench("foo", async (t) => { const resource = setup(); // not included in measurement t.start(); measuredOperation(resource); t.end(); resource.close(); // not included in measurement }); ```
50 lines
941 B
TypeScript
50 lines
941 B
TypeScript
Deno.bench("start and end", (t) => {
|
|
const id = setInterval(() => {}, 1000);
|
|
t.start();
|
|
Deno.inspect(id);
|
|
t.end();
|
|
clearInterval(id);
|
|
});
|
|
|
|
Deno.bench("start only", (t) => {
|
|
const id = setInterval(() => {}, 1000);
|
|
t.start();
|
|
Deno.inspect(id);
|
|
clearInterval(id);
|
|
});
|
|
|
|
Deno.bench("end only", (t) => {
|
|
const id = setInterval(() => {}, 1000);
|
|
Deno.inspect(id);
|
|
t.end();
|
|
clearInterval(id);
|
|
});
|
|
|
|
Deno.bench("double start", (t) => {
|
|
const id = setInterval(() => {}, 1000);
|
|
t.start();
|
|
t.start();
|
|
Deno.inspect(id);
|
|
t.end();
|
|
clearInterval(id);
|
|
});
|
|
|
|
let captured: Deno.BenchContext;
|
|
|
|
Deno.bench("double end", (t) => {
|
|
captured = t;
|
|
const id = setInterval(() => {}, 1000);
|
|
t.start();
|
|
Deno.inspect(id);
|
|
t.end();
|
|
t.end();
|
|
clearInterval(id);
|
|
});
|
|
|
|
Deno.bench("captured", () => {
|
|
const id = setInterval(() => {}, 1000);
|
|
captured!.start();
|
|
Deno.inspect(id);
|
|
captured!.end();
|
|
clearInterval(id);
|
|
});
|