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'
|
|
|
|
|
2020-09-30 15:34:26 +09:00
|
|
|
import { benchAsync } from './async'
|
2020-12-21 17:10:30 +09:00
|
|
|
import { benchBuffer } from './buffer'
|
2020-12-29 19:03:10 +09:00
|
|
|
import { benchGetSetProperty } from './get-set-property'
|
2020-09-30 15:34:26 +09:00
|
|
|
import { benchNoop } from './noop'
|
|
|
|
import { benchPlus } from './plus'
|
|
|
|
|
|
|
|
async function run() {
|
2020-12-21 17:10:30 +09:00
|
|
|
const output = [
|
|
|
|
await benchNoop(),
|
|
|
|
await benchPlus(),
|
|
|
|
await benchBuffer(),
|
2020-12-29 19:03:10 +09:00
|
|
|
await benchGetSetProperty(),
|
2020-12-21 17:10:30 +09:00
|
|
|
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')
|
2020-09-30 15:34:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
run().catch((e) => {
|
|
|
|
console.error(e)
|
|
|
|
})
|