run: pnpm install --ignore-scripts --frozen-lockfile
- uses: bencherdev/bencher@main
- name: Run production benchmark
+ run: pnpm benchmark:tinybench:prod
+ - name: Publish benchmark
+ shell: bash
run: |
+ args=()
+ if [[ "$GITHUB_REF" != refs/heads/master ]]; then
+ args+=(--dry-run)
+ fi
bencher run \
- --branch master \
+ "${args[@]}" \
+ --branch "$GITHUB_REF_NAME" \
--threshold-measure latency \
--threshold-test t_test \
--threshold-max-sample-size 64 \
--threshold-upper-boundary _ \
--thresholds-reset \
--file benchmark-report.json \
- --err \
- --github-actions ${{ secrets.GITHUB_TOKEN }} \
- "pnpm benchmark:tinybench:prod"
+ --err
import { strictEqual } from 'node:assert'
-import { Bench } from 'tinybench'
+import { Bench, mToNs } from 'tinybench'
import {
DynamicClusterPool,
const bmfResults = {}
let pool
try {
- const bench = new Bench()
+ const bench = new Bench({ throws: true })
pool = buildPoolifierPool(workerType, poolType, poolSize)
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
console.table(bench.table())
for (const task of tasks) {
- if (
- task.result?.state === 'completed' ||
- task.result?.state === 'aborted-with-statistics'
- ) {
- bmfResults[task.name] = {
- latency: {
- lower_value: task.result.latency.mean - task.result.latency.sd,
- upper_value: task.result.latency.mean + task.result.latency.sd,
- value: task.result.latency.mean,
- },
- throughput: {
- lower_value:
- task.result.throughput.mean - task.result.throughput.sd,
- upper_value:
- task.result.throughput.mean + task.result.throughput.sd,
- value: task.result.throughput.mean,
- },
- }
+ if (task.result?.state !== 'completed') {
+ throw new Error(`Benchmark did not complete: ${task.name}`)
+ }
+ bmfResults[task.name] = {
+ latency: {
+ // Tinybench reports milliseconds; Bencher latency uses nanoseconds.
+ lower_value: mToNs(task.result.latency.mean - task.result.latency.sd),
+ upper_value: mToNs(task.result.latency.mean + task.result.latency.sd),
+ value: mToNs(task.result.latency.mean),
+ },
+ throughput: {
+ lower_value: task.result.throughput.mean - task.result.throughput.sd,
+ upper_value: task.result.throughput.mean + task.result.throughput.sd,
+ value: task.result.throughput.mean,
+ },
}
}
return bmfResults
- } catch (error) {
- console.error(error)
- return bmfResults
} finally {
if (pool != null) {
await pool.destroy()