summaryrefslogtreecommitdiff
path: root/cli/tests/testdata/bench/explicit_start_and_end.ts
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-07-31 11:02:59 +0100
committerGitHub <noreply@github.com>2023-07-31 12:02:59 +0200
commit02865cb5a270b9a2229863e83582f2a8b5115b78 (patch)
tree56529bdc267d6779be2efb8c92e58119e3687f24 /cli/tests/testdata/bench/explicit_start_and_end.ts
parente348c11b64410cf91bd5925ffbc5a9009947a80f (diff)
feat(bench): add BenchContext::start() and BenchContext::end() (#18734)
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 }); ```
Diffstat (limited to 'cli/tests/testdata/bench/explicit_start_and_end.ts')
-rw-r--r--cli/tests/testdata/bench/explicit_start_and_end.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/cli/tests/testdata/bench/explicit_start_and_end.ts b/cli/tests/testdata/bench/explicit_start_and_end.ts
new file mode 100644
index 000000000..60a3d10d7
--- /dev/null
+++ b/cli/tests/testdata/bench/explicit_start_and_end.ts
@@ -0,0 +1,50 @@
+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);
+});