diff --git a/Cargo.lock b/Cargo.lock index 48a21233..7a86252e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -130,15 +130,6 @@ dependencies = [ "shlex", ] -[[package]] -name = "cedarwood" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0524a528a6a0288df1863c3c20fe92c301875b4941e7b6c4b394ab08c5a4c55" -dependencies = [ - "smallvec", -] - [[package]] name = "cfg-if" version = "1.0.4" @@ -410,12 +401,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "fastrand" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" - [[package]] name = "ff" version = "0.13.1" @@ -690,26 +675,20 @@ checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "jieba-macros" -version = "0.10.3" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34904340bc65749a9e9a02fcc7f3368e675427c18447b9bbe02df52c15c9a36a" -dependencies = [ - "phf_codegen", -] +checksum = "2987cf45b1bfdb4ff1f6a814b1aa2ad6361f4ff43bf353a9bd29f391a9568f70" [[package]] name = "jieba-rs" -version = "0.10.3" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb5bdea4dc241d589e179f39d2a778f31490f3370aa2f626223dbd930ebc5c9d" +checksum = "0a3a7d02ea31e6fc6f2fe10495dc7c5efcf381e1f21d7172f58ba792efa1c2fd" dependencies = [ "bytecount", - "cedarwood", "include-flate", "jieba-macros", "ordered-float", - "phf", - "regex", "rustc-hash", ] @@ -1106,45 +1085,6 @@ dependencies = [ "base64ct", ] -[[package]] -name = "phf" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" -dependencies = [ - "phf_shared", - "serde", -] - -[[package]] -name = "phf_codegen" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49aa7f9d80421bca176ca8dbfebe668cc7a2684708594ec9f3c0db0805d5d6e1" -dependencies = [ - "phf_generator", - "phf_shared", -] - -[[package]] -name = "phf_generator" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737" -dependencies = [ - "fastrand", - "phf_shared", -] - -[[package]] -name = "phf_shared" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project-lite" version = "0.2.17" @@ -1501,12 +1441,6 @@ dependencies = [ "time", ] -[[package]] -name = "siphasher" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ee5873ec9cce0195efcb7a4e9507a04cd49aec9c83d0389df45b1ef7ba2e649" - [[package]] name = "slab" version = "0.4.12" diff --git a/Cargo.toml b/Cargo.toml index d73ea36a..73eead9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/packages/jieba/README.md b/packages/jieba/README.md index 44041a0e..ec8833cd 100644 --- a/packages/jieba/README.md +++ b/packages/jieba/README.md @@ -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 Name │ ops/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 name │ Latency 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 Name │ ops/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 name │ Latency 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 Name │ ops/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 name │ Latency 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 Name │ ops/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 name │ Latency 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 diff --git a/packages/jieba/benchmark/jieba.ts b/packages/jieba/benchmark/jieba.ts index fa2a2c1c..764ad838 100644 --- a/packages/jieba/benchmark/jieba.ts +++ b/packages/jieba/benchmark/jieba.ts @@ -31,6 +31,7 @@ async function createBench(suitename: string, napi: () => any[]) { await suite.run() + console.info(`Benchmark ${suitename} result`) console.table(suite.table()) }