Comments (4)
原因来自于注释了
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
重新测试后的结果如下
napi @ Small input x 2,459,825 ops/sec ±0.38% (89 runs sampled)
napi#buff @ Small input x 2,947,302 ops/sec ±0.15% (93 runs sampled)
napi#asyncBuff @ Small input x 108,739 ops/sec ±0.49% (83 runs sampled)
javascript @ Small input x 2,554,025 ops/sec ±0.13% (99 runs sampled)
Small input bench suite: Fastest is napi#buff @ Small input
from fast-escape.
allocator
会极大程度的影响对内存频繁申请释放的程序性能
from fast-escape.
对于我另外一个案例似乎不起作用,且目前性能差异相距甚大,请教一下可以有哪些具体的优化方向?(例如:simd)
正则转换 html 内容类似 <div>{{ data }}</div>
编译为 <div>hello</div>
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 结果
CompileHtmlStr#Node x 5,543,011 ops/sec ±1.16% (88 runs sampled)
CompileHtmlStr#Rust x 43,318 ops/sec ±0.47% (95 runs sampled)
Fastest is CompileHtmlStr#Node
from fast-escape.
regex
这个包的 SIMD 加速效果不如 escape 这个场景这么明显,无法抵消 Node-API call overhead 的消耗
from fast-escape.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast-escape.