Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): Add examples, and taskName to easily print the benchmβ¦
β¦arking results
- Loading branch information
1 parent
21d1538
commit 7937010
Showing
9 changed files
with
432 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../.eslintrc.json", | ||
"include": [ | ||
"src/*.ts" | ||
] | ||
} |
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,15 @@ | ||
{ | ||
"name": "examples", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc", | ||
"simple": "tsx src/simple.ts", | ||
"dev:simple": "tsx watch src/simple.ts" | ||
}, | ||
"license": "ISC", | ||
"devDependencies": { | ||
"tsx": "^3.9.0", | ||
"typescript": "^4.5.4" | ||
} | ||
} |
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,31 @@ | ||
import { Bench } from '../../src'; | ||
|
||
const bench = new Bench({ time: 100 }); | ||
|
||
bench | ||
.add('switch 1', () => { | ||
let a = 1; | ||
let b = 2; | ||
const c = a; | ||
a = b; | ||
b = c; | ||
}) | ||
.add('switch 2', () => { | ||
let a = 1; | ||
let b = 10; | ||
a = b + a; | ||
b = a - b; | ||
a = b - a; | ||
}); | ||
|
||
await bench.run(); | ||
|
||
console.table(bench.results.map((result) => ({ "Task Name": result?.taskName, "Average Time (ps)": result?.mean! * 1000, "Variance (ps)": result?.variance! * 1000 }))); | ||
|
||
// Output: | ||
// βββββββββββ¬βββββββββββββ¬βββββββββββββββββββββ¬βββββββββββββββββββββ | ||
// β (index) β Task Name β Average Time (ps) β Variance (ps) β | ||
// βββββββββββΌβββββββββββββΌβββββββββββββββββββββΌβββββββββββββββββββββ€ | ||
// β 0 β 'switch 1' β 1.8458325710527104 β 1.2113875253341617 β | ||
// β 1 β 'switch 2' β 1.8746935152109603 β 1.2254725890767446 β | ||
// βββββββββββ΄βββββββββββββ΄βββββββββββββββββββββ΄βββββββββββββββββββββ |
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,16 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": [ | ||
"src/*.ts" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
], | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"baseUrl": ".", | ||
"outDir": "dist" | ||
}, | ||
} |
Oops, something went wrong.