napi-rs/bench/get-array-from-js.ts

28 lines
565 B
TypeScript
Raw Normal View History

2021-05-14 00:36:39 +09:00
import b from 'benny'
const {
getArrayFromJson,
getArrayFromJsArray,
getArrayWithForLoop,
} = require('./index.node')
const FIXTURE = Array.from({ length: 1000 }).fill(42)
export const benchGetArray = () =>
b.suite(
'getArrayFromJs',
b.add('get array from json string', () => {
getArrayFromJson(JSON.stringify(FIXTURE))
}),
b.add('get array from serde', () => {
getArrayFromJsArray(FIXTURE)
}),
b.add('get array with for loop', () => {
getArrayWithForLoop(FIXTURE)
}),
b.cycle(),
b.complete(),
)