2020-09-30 15:34:26 +09:00
|
|
|
import b from 'benny'
|
|
|
|
|
2020-12-28 15:02:28 +09:00
|
|
|
const { benchAsyncTask, benchThreadsafeFunction } = require('./index.node')
|
2020-09-30 15:34:26 +09:00
|
|
|
|
|
|
|
const buffer = Buffer.from('hello 🚀 rust!')
|
|
|
|
|
|
|
|
export const benchAsync = () =>
|
|
|
|
b.suite(
|
|
|
|
'Async task',
|
2020-12-28 15:02:28 +09:00
|
|
|
b.add('spawn task', async () => {
|
2020-09-30 15:34:26 +09:00
|
|
|
await benchAsyncTask(buffer)
|
|
|
|
}),
|
2020-12-28 15:02:28 +09:00
|
|
|
b.add('thread safe function', async () => {
|
|
|
|
await new Promise<number | undefined>((resolve, reject) => {
|
|
|
|
benchThreadsafeFunction(buffer, (err?: Error, value?: number) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve(value)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}),
|
2020-09-30 15:34:26 +09:00
|
|
|
b.cycle(),
|
|
|
|
b.complete(),
|
|
|
|
)
|