-
-
Notifications
You must be signed in to change notification settings - Fork 151
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 suite & formatters, update benchmark()
- add `suite()` benchmark runner - update `BenchmarkOpts` & `benchmark()` - add `size` option to configure calls per iteration - add `format` option to configure formatter - add `BenchmarkFormatter` interface - add `FORMAT_DEFAULT`, `FORMAT_CSV` & `FORMAT_MD` formatters
- Loading branch information
1 parent
0329b7b
commit 5ea02bd
Showing
10 changed files
with
353 additions
and
26 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
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,22 @@ | ||
import { BenchmarkFormatter, EMPTY, FLOAT } from "../api"; | ||
|
||
export const FORMAT_CSV: BenchmarkFormatter = { | ||
prefix: () => `Title,Iterations,Size,Total,Mean,Median,Min,Max,Q1,Q3,SD%`, | ||
start: EMPTY, | ||
warmup: EMPTY, | ||
result: (res) => | ||
`"${res.title}",${res.iter},${res.size},${[ | ||
res.total, | ||
res.mean, | ||
res.median, | ||
res.min, | ||
res.max, | ||
res.q1, | ||
res.q3, | ||
res.sd, | ||
] | ||
.map(FLOAT) | ||
.join(",")}`, | ||
total: EMPTY, | ||
suffix: EMPTY, | ||
}; |
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,18 @@ | ||
import { BenchmarkFormatter, EMPTY, FLOAT } from "../api"; | ||
|
||
export const FORMAT_DEFAULT: BenchmarkFormatter = { | ||
prefix: EMPTY, | ||
start: ({ title }) => `benchmarking: ${title}`, | ||
warmup: (t, { warmup }) => `\twarmup... ${FLOAT(t)}ms (${warmup} runs)`, | ||
result: ({ iter, size, total, mean, median, min, max, q1, q3, sd }) => | ||
// prettier-ignore | ||
`\ttotal: ${FLOAT(total)}ms, runs: ${iter} (@ ${size} calls/iter) | ||
\tmean: ${FLOAT(mean)}ms, median: ${FLOAT(median)}ms, range: [${FLOAT(min)}..${FLOAT(max)}] | ||
\tq1: ${FLOAT(q1)}ms, q3: ${FLOAT(q3)}ms | ||
\tsd: ${FLOAT(sd)}%`, | ||
total: (res) => { | ||
const fastest = res.slice().sort((a, b) => a.mean - b.mean)[0]; | ||
return `Fastest: "${fastest.title}"`; | ||
}, | ||
suffix: () => `---`, | ||
}; |
Oops, something went wrong.