-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 }); ```
- Loading branch information
Showing
7 changed files
with
258 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
cpu: [WILDCARD] | ||
runtime: deno [WILDCARD] ([WILDCARD]) | ||
|
||
[WILDCARD]/explicit_start_and_end.ts | ||
benchmark time (avg) (min … max) p75 p99 p995 | ||
----------------------------------------------------- ----------------------------- | ||
start and end [WILDCARD] [WILDCARD]/iter[WILDCARD]([WILDCARD] … [WILDCARD]) [WILDCARD] | ||
start only [WILDCARD] [WILDCARD]/iter[WILDCARD]([WILDCARD] … [WILDCARD]) [WILDCARD] | ||
end only [WILDCARD] [WILDCARD]/iter[WILDCARD]([WILDCARD] … [WILDCARD]) [WILDCARD] | ||
double start error: TypeError: BenchContext::start() has already been invoked. | ||
t.start(); | ||
^ | ||
at BenchContext.start ([WILDCARD]) | ||
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] | ||
double end error: TypeError: BenchContext::end() has already been invoked. | ||
t.end(); | ||
^ | ||
at BenchContext.end ([WILDCARD]) | ||
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] | ||
captured error: TypeError: The benchmark which this context belongs to is not being executed. | ||
captured!.start(); | ||
^ | ||
at BenchContext.start ([WILDCARD]) | ||
at [WILDCARD]/explicit_start_and_end.ts:[WILDCARD] | ||
error: Bench failed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.