Skip to content
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

fix benchmarks: replace nanobench with bipbip #165

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

milahu
Copy link

@milahu milahu commented Aug 31, 2023

purpose

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

alternative to #164

before

$ npm run benchmark

> [email protected] 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

> [email protected] 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
Copy link

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

🚮 Removed packages: [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant