napi-rs/bench/bench.ts

42 lines
1 KiB
TypeScript
Raw Normal View History

2020-10-14 01:18:12 +09:00
import { promises as fs } from 'fs'
import { join } from 'path'
import { Summary } from 'benny/lib/internal/common-types'
import { benchAsync } from './async'
import { benchBuffer } from './buffer'
2021-05-14 00:36:39 +09:00
import { benchCreateArray } from './create-array'
import { benchGetArray } from './get-array-from-js'
import { benchGetSetProperty } from './get-set-property'
import { benchNoop } from './noop'
import { benchPlus } from './plus'
async function run() {
const output = [
await benchNoop(),
await benchPlus(),
await benchBuffer(),
2021-05-14 00:36:39 +09:00
await benchCreateArray(),
await benchGetArray(),
await benchGetSetProperty(),
await benchAsync(),
]
2020-10-14 01:18:12 +09:00
.map(formatSummary)
.join('\n')
await fs.writeFile(join(process.cwd(), 'bench.txt'), output, 'utf8')
}
function formatSummary(summary: Summary): string {
return summary.results
.map(
(result) =>
`${summary.name}#${result.name} x ${result.ops} ops/sec ±${result.margin}% (${result.samples} runs sampled)`,
)
.join('\n')
}
run().catch((e) => {
console.error(e)
})