webtorrent / node-bencode

bencode de/encoder for nodejs
MIT License
166 stars 36 forks source link

fix benchmarks: replace nanobench with bipbip #165

Open milahu opened 1 year ago

milahu commented 1 year ago

purpose

[ ] Documentation update [x] Bug fix [ ] New feature [ ] Other

alternative to #164

before

$ npm run benchmark

> bencode@4.0.0 benchmark
> nanobench benchmark/*.js

/tmp/node-bencode/node_modules/nanobench/run.js:7
for (let i = 2; i < process.argv.length; i++) require(path.join(process.cwd(), process.argv[i]))
                                              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /tmp/node-bencode/benchmark/bencode.js from /tmp/node-bencode/node_modules/nanobench/run.js not supported.
Instead change the require of bencode.js in /tmp/node-bencode/nanobench/run.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/tmp/node-bencode/node_modules/nanobench/run.js:7:47) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v20.3.1

after

$ npm run benchmark

> bencode@4.0.0 benchmark
> bipbip --compare benchmark/benchmarks.json --save benchmark/benchmarks.json benchmark/benchmarks.js

reference before benchmarks
  ✔ fibonacci loop: 1,786,717 ops/sec (±3.15%, ⨉1000000)
  ✔ fibonacci recursive: 1,586 ops/sec (±1.01%, ⨉7934)
  ✔ fibonacci recmemo: 125,864 ops/sec (±0.57%, ⨉629322)

bencode
  ✔ bencode.encode() [buffer]: 7,025 ops/sec (±1.22%, ⨉35127)
  ✔ bencode.encode() [utf8]: 269 ops/sec (±0.68%, ⨉1349)
  ✔ bencode.encode() [ascii]: 277 ops/sec (±0.70%, ⨉1387)
  ✔ bencode.encode() [binary]: 276 ops/sec (±0.89%, ⨉1384)
  ✔ bencode.decode() [buffer]: 8,561 ops/sec (±0.73%, ⨉42809)
  ✔ bencode.decode() [utf8]: 462 ops/sec (±0.64%, ⨉2313)
  ✔ bencode.decode() [ascii]: 481 ops/sec (±0.55%, ⨉2409)
  ✔ bencode.decode() [binary]: 479 ops/sec (±0.54%, ⨉2396)

buffer vs string
  ✔ decode buffer: 9,004 ops/sec (±0.51%, ⨉45024)
  ✔ decode string: 5,594 ops/sec (±0.50%, ⨉27973)

compare decode
  ✔ bencode.decode(): 8,913 ops/sec (±0.53%, ⨉44568)
  ✔ bencoding.decode(): 10,845 ops/sec (±0.55%, ⨉54228)
  ✔ bncode.decode(): 314 ops/sec (±4.03%, ⨉1570)
  ✔ btparse(): 26,465 ops/sec (±0.49%, ⨉132325)
  ✔ dht.decode(): 9,480 ops/sec (±0.47%, ⨉47400)
  ✔ dhtBencode.decode(): 5,754 ops/sec (±0.49%, ⨉28774)

compare encode
  ✔ bencode.encode(): 7,533 ops/sec (±0.83%, ⨉37666)
  ✔ bencoding.encode(): 5 ops/sec (±8.55%, ⨉25)
  ✔ bncode.encode(): 3.9s per call (±0.00%, ⨉1)
  ✔ dht.encode(): 10 ops/sec (±6.32%, ⨉50)
  ✔ dhtBencode.encode(): 2 ops/sec (±9.90%, ⨉14)

encoding length
  ✔ bencode.encodingLength(torrent): 32,470 ops/sec (±2.61%, ⨉162351)
  ✔ bencode.encodingLength(buffer): 868,415 ops/sec (±0.17%, ⨉1000000)
  ✔ bencode.encodingLength(string): 228,075 ops/sec (±0.33%, ⨉1000000)
  ✔ bencode.encodingLength(number): 1,793,989 ops/sec (±0.30%, ⨉1000000)
  ✔ bencode.encodingLength(array<number>): 359,102 ops/sec (±0.20%, ⨉1000000)
  ✔ bencode.encodingLength(small object): 62,385 ops/sec (±0.34%, ⨉311927)

reference after benchmarks
  ✔ fibonacci loop: 1,451,201 ops/sec (±0.23%, ⨉1000000)
  ✔ fibonacci recursive: 1,416 ops/sec (±0.96%, ⨉7080)
  ✔ fibonacci recmemo: 122,878 ops/sec (±0.22%, ⨉614393)

Result:    0.00%   
Suites:    7 total 
Scenarios: 33 total
Time:      2m 45.7s
socket-security[bot] commented 1 year ago

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: nanobench@3.0.0