-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2a1d2d
commit 4bc00e4
Showing
9 changed files
with
66 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Bench } from 'tinybench' | ||
|
||
const bench = new Bench({ time: 100 }) | ||
|
||
bench | ||
.add('faster task', () => { | ||
console.log('I am faster') | ||
}) | ||
.add('slower task', async () => { | ||
await new Promise(r => setTimeout(r, 1)) // we wait 1ms :) | ||
console.log('I am slower') | ||
}) | ||
.todo('unimplemented bench') | ||
|
||
await bench.warmup() // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50 | ||
await bench.run() | ||
|
||
console.table(bench.table()) | ||
|
||
// Output: | ||
// ┌─────────┬───────────────┬──────────┬────────────────────┬───────────┬─────────┐ | ||
// │ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │ | ||
// ├─────────┼───────────────┼──────────┼────────────────────┼───────────┼─────────┤ | ||
// │ 0 │ 'faster task' │ '41,621' │ 24025.791819761525 │ '±20.50%' │ 4257 │ | ||
// │ 1 │ 'slower task' │ '828' │ 1207382.7838323202 │ '±7.07%' │ 83 │ | ||
// └─────────┴───────────────┴──────────┴────────────────────┴───────────┴─────────┘ | ||
|
||
console.table( | ||
bench.table((task) => ({ 'Task name': task.name })) | ||
) | ||
|
||
// Output: | ||
// ┌─────────┬───────────────────────┐ | ||
// │ (index) │ Task name │ | ||
// ├─────────┼───────────────────────┤ | ||
// │ 0 │ 'unimplemented bench' │ | ||
// └─────────┴───────────────────────┘ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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