2020-12-21 17:10:30 +09:00
|
|
|
use napi::{ContextlessResult, Env, JsBuffer, JsObject, Result};
|
|
|
|
|
|
|
|
#[contextless_function]
|
|
|
|
pub fn bench_create_buffer(env: Env) -> ContextlessResult<JsBuffer> {
|
2021-06-22 00:09:13 +09:00
|
|
|
let mut output = Vec::with_capacity(1024);
|
2020-12-21 17:10:30 +09:00
|
|
|
output.push(1);
|
|
|
|
output.push(2);
|
|
|
|
env
|
|
|
|
.create_buffer_with_data(output)
|
|
|
|
.map(|v| Some(v.into_raw()))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn register_js(exports: &mut JsObject) -> Result<()> {
|
|
|
|
exports.create_named_method("benchCreateBuffer", bench_create_buffer)?;
|
|
|
|
Ok(())
|
|
|
|
}
|