-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
性能疑问 #214
Comments
原因来自于注释了
重新测试后的结果如下
|
|
对于我另外一个案例似乎不起作用,且目前性能差异相距甚大,请教一下可以有哪些具体的优化方向?(例如:simd) 正则转换 html 内容类似 js exports.compileHtmlStr = (html, data) => {
const reg = new RegExp(/{{\s*data\s*}}/g)
return html.replace(reg, data)
} napi + rust #[macro_use]
extern crate napi_derive;
use regex::Regex;
use napi::{JsObject, JsString, Result, CallContext};
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
#[module_exports]
fn init(mut exports: JsObject) -> Result<()> {
exports.create_named_method("compileHtmlStr", compile_html_str)?;
Ok(())
}
#[js_function(2)]
fn compile_html_str(ctx: CallContext) -> Result<JsString> {
let html = ctx.get::<JsString>(0)?.into_utf8()?;
let data = ctx.get::<JsString>(1)?.into_utf8()?;
let reg = Regex::new(r"\{\{\s*data\s*\}\}").unwrap();
let c_html = reg.replace_all(html.as_str()?, data.as_str()?);
ctx.env.create_string_from_std(c_html.to_string())
} 测试 bench 结果
|
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
在本地测试
Small input
中 javascript 性能比 napi 高效The text was updated successfully, but these errors were encountered: