Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 4 additions & 70 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ crc32c = { version = "0.6" }
crc32fast = { version = "1.4", features = ["nightly"] }
global_alloc = { path = "./crates/alloc" }
indexmap = { version = "2", features = ["serde"] }
jieba-rs = { version = "0.10", default-features = false, features = ["tfidf", "textrank"] }
jieba-rs = { version = "0.11", default-features = false, features = ["tfidf", "textrank"] }
jsonwebtoken = { version = "11", features = ["rust_crypto"] }
mimalloc-safe = "0.1"
napi = { version = "3", default-features = false, features = ["napi3"] }
Expand Down
50 changes: 26 additions & 24 deletions packages/jieba/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,37 @@

Due to [jieba-rs is 33% faster than cppjieba](https://blog.paulme.ng/posts/2019-06-30-optimizing-jieba-rs-to-be-33percents-faster-than-cppjieba.html), and N-API is faster than `v8` C++ API, `@node-rs/jieba` is faster than `nodejieba`.

Benchmarked with `jieba-rs@0.11.0` vs `nodejieba@3.5.8` on Apple M4 Max, Node.js v26.8.2:

```bash
Benchmark Cut 1184 words result
┌─────────┬──────────────────┬─────────┬────────────────────┬──────────┬─────────┐
│ (index) │ Task Nameops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────┼─────────┼────────────────────┼──────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '8,246' │ 121266.9342871014 │ '±0.17%' │ 4124
│ 1 │ 'nodejieba' │ '6,392' │ 156439.52799499547 │ '±0.20%' │ 3197
└─────────┴──────────────────┴─────────┴────────────────────┴──────────┴─────────┘
┌─────────┬──────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task nameLatency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼──────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '61311 ± 0.08%' │ '61041 ± 416.00' │ '16342 ± 0.06%' │ '16382 ± 111' │ 16311
│ 1 │ 'nodejieba' │ '133632 ± 0.11%' │ '133875 ± 1667.0' │ '7497 ± 0.09%' │ '7470 ± 92' │ 7484
└─────────┴──────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘
Benchmark Cut 246568 words result
┌─────────┬──────────────────┬─────────┬──────────────────────────────┬─────────┐
│ (index) │ Task Nameops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────┼─────────┼──────────────────────────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '32' │ 30760703.470588237 │ '±3.01%' │ 17
│ 1 │ 'nodejieba' │ '19' │ 51275112.699999996 │ '±2.68%' │ 10
└─────────┴──────────────────┴─────────┴──────────────────────────────┴─────────┘
┌─────────┬──────────────────┬────────────────────┬─────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task nameLatency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼──────────────────┼────────────────────┼─────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '17941189 ± 1.06%' │ '17739146 ± 215874' │ '56 ± 0.98%' │ '56 ± 1' │ 64
│ 1 │ 'nodejieba' │ '39167640 ± 1.22%' │ '38399145 ± 888271' │ '26 ± 1.15%' │ '26 ± 1' │ 64
└─────────┴──────────────────┴────────────────────┴─────────────────────┴────────────────────────┴────────────────────────┴─────────┘
Benchmark Tag 1184 words result
┌─────────┬──────────────────┬─────────┬───────────────────┬──────────┬─────────┐
│ (index) │ Task Nameops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────┼─────────┼───────────────────┼──────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '3,174' │ 315048.8916876547 │ '±0.20%' │ 1588
│ 1 │ 'nodejieba' │ '2,672' │ 374213.8870605615 │ '±0.23%' │ 1337
└─────────┴──────────────────┴─────────┴───────────────────┴──────────┴─────────┘
┌─────────┬──────────────────┬──────────────────┬───────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task nameLatency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼──────────────────┼──────────────────┼───────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '158515 ± 0.09%' │ '157416 ± 1249.0' │ '6315 ± 0.07%' │ '6353 ± 51' │ 6309
│ 1 │ 'nodejieba' │ '305060 ± 0.12%' │ '303375 ± 2541.0' │ '3281 ± 0.10%' │ '3296 ± 27' │ 3279
└─────────┴──────────────────┴──────────────────┴───────────────────┴────────────────────────┴────────────────────────┴─────────┘
Benchmark Tag 246568 words result
┌─────────┬──────────────────┬─────────┬──────────────────────────────┬─────────┐
│ (index) │ Task Nameops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────┼─────────┼──────────────────────────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '11' │ 84886341.7999999 │ '±5.74%' │ 10
│ 1 │ 'nodejieba' │ '7' 125781083.30000004 │ '±4.75%' │ 10
└─────────┴──────────────────┴─────────┴──────────────────────────────┴─────────┘
┌─────────┬──────────────────┬────────────────────┬──────────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task nameLatency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼──────────────────┼────────────────────┼──────────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ '@node-rs/jieba' │ '42167642 ± 1.49%' │ '41271917 ± 769729' │ '24 ± 1.36%' │ '24 ± 0' │ 64
│ 1 │ 'nodejieba' │ '86278741 ± 0.86%' │ '85348500 ± 1364291''12 ± 0.83%' │ '12 ± 0' │ 64
└─────────┴──────────────────┴────────────────────┴──────────────────────┴────────────────────────┴────────────────────────┴─────────┘
```

## Usage
Expand Down
1 change: 1 addition & 0 deletions packages/jieba/benchmark/jieba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async function createBench(suitename: string, napi: () => any[]) {

await suite.run()

console.info(`Benchmark ${suitename} result`)
console.table(suite.table())
}

Expand Down
Loading