2020-09-30 15:34:26 +09:00
|
|
|
import b from 'benny'
|
|
|
|
|
2021-06-03 00:03:47 +09:00
|
|
|
const {
|
|
|
|
benchAsyncTask,
|
|
|
|
benchThreadsafeFunction,
|
|
|
|
benchTokioFuture,
|
|
|
|
} = 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)
|
|
|
|
}),
|
2021-06-03 00:03:47 +09:00
|
|
|
b.add('ThreadSafeFunction', async () => {
|
2020-12-28 15:02:28 +09:00
|
|
|
await new Promise<number | undefined>((resolve, reject) => {
|
|
|
|
benchThreadsafeFunction(buffer, (err?: Error, value?: number) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
} else {
|
|
|
|
resolve(value)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}),
|
2021-06-03 00:03:47 +09:00
|
|
|
b.add('Tokio future to Promise', async () => {
|
|
|
|
await benchTokioFuture(buffer)
|
|
|
|
}),
|
2020-09-30 15:34:26 +09:00
|
|
|
b.cycle(),
|
|
|
|
b.complete(),
|
|
|
|
)
|