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 tinybench #164

Open
wants to merge 1 commit 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

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
> node benchmark/all.js

┌─────────┬─────────────────────────┬─────────┬────────────────────┬───────────┬─────────┐
│ (index) │        Task Name        │ ops/sec │ Average Time (ns)  │  Margin   │ Samples │
├─────────┼─────────────────────────┼─────────┼────────────────────┼───────────┼─────────┤
│    0    │ 'decode buffer ⨉ 10000' │ '3,109' │ 321637.03556612757 │ '±18.80%' │   311   │
│    1    │ 'decode string ⨉ 10000' │ '7,520' │ 132977.82539529787 │ '±1.35%'  │   753   │
└─────────┴─────────────────────────┴─────────┴────────────────────┴───────────┴─────────┘
┌─────────┬───────────────────────────────┬─────────┬────────────────────┬──────────┬─────────┐
│ (index) │           Task Name           │ ops/sec │ Average Time (ns)  │  Margin  │ Samples │
├─────────┼───────────────────────────────┼─────────┼────────────────────┼──────────┼─────────┤
│    0    │  'bencode.encode() ⨉ 10000'   │ '4,915' │ 203449.76826411922 │ '±4.16%' │   492   │
│    1    │ 'bencoding.encode() ⨉ 10000'  │ '7,867' │ 127099.88481359227 │ '±1.11%' │   787   │
│    2    │   'bncode.encode() ⨉ 10000'   │ '5,204' │ 192149.96678357848 │ '±1.63%' │   521   │
│    3    │    'dht.encode() ⨉ 10000'     │ '7,086' │ 141112.21156100123 │ '±2.91%' │   709   │
│    4    │ 'dhtBencode.encode() ⨉ 10000' │ '7,323' │ 136541.21890725088 │ '±1.50%' │   733   │
└─────────┴───────────────────────────────┴─────────┴────────────────────┴──────────┴─────────┘
┌─────────┬───────────────────────────────┬─────────┬────────────────────┬──────────┬─────────┐
│ (index) │           Task Name           │ ops/sec │ Average Time (ns)  │  Margin  │ Samples │
├─────────┼───────────────────────────────┼─────────┼────────────────────┼──────────┼─────────┤
│    0    │  'bencode.decode() ⨉ 10000'   │ '5,739' │  174245.10081886   │ '±3.51%' │   574   │
│    1    │ 'bencoding.decode() ⨉ 10000'  │ '7,735' │ 129266.9797744554  │ '±2.50%' │   774   │
│    2    │   'bncode.decode() ⨉ 10000'   │ '4,926' │ 202983.70483197257 │ '±1.43%' │   493   │
│    3    │      'btparse() ⨉ 10000'      │ '7,609' │  131418.479726443  │ '±1.24%' │   761   │
│    4    │    'dht.decode() ⨉ 10000'     │ '7,739' │ 129204.64933380598 │ '±1.09%' │   774   │
│    5    │ 'dhtBencode.decode() ⨉ 10000' │ '7,619' │ 131236.25250938997 │ '±1.86%' │   762   │
└─────────┴───────────────────────────────┴─────────┴────────────────────┴──────────┴─────────┘
┌─────────┬─────────────────────────────────────────┬─────────┬────────────────────┬──────────┬─────────┐
│ (index) │                Task Name                │ ops/sec │ Average Time (ns)  │  Margin  │ Samples │
├─────────┼─────────────────────────────────────────┼─────────┼────────────────────┼──────────┼─────────┤
│    0    │    'bencode.encodingLength(torrent)'    │ '6,646' │ 150445.01670321127 │ '±1.67%' │   665   │
│    1    │    'bencode.encodingLength(buffer)'     │ '7,696' │ 129933.3417570436  │ '±2.05%' │   770   │
│    2    │    'bencode.encodingLength(string)'     │ '6,143' │ 162767.33817123785 │ '±2.25%' │   615   │
│    3    │    'bencode.encodingLength(number)'     │ '7,701' │ 129849.4954362763  │ '±1.10%' │   771   │
│    4    │ 'bencode.encodingLength(array<number>)' │ '7,362' │ 135820.64856344194 │ '±2.03%' │   737   │
│    5    │ 'bencode.encodingLength(small object)'  │ '5,327' │ 187717.5960934408  │ '±2.38%' │   533   │
└─────────┴─────────────────────────────────────────┴─────────┴────────────────────┴──────────┴─────────┘
┌─────────┬─────────────────────────────────────┬─────────┬────────────────────┬──────────┬─────────┐
│ (index) │              Task Name              │ ops/sec │ Average Time (ns)  │  Margin  │ Samples │
├─────────┼─────────────────────────────────────┼─────────┼────────────────────┼──────────┼─────────┤
│    0    │ 'bencode.encode() [buffer] ⨉ 10000' │ '5,753' │ 173813.93081612058 │ '±5.72%' │   576   │
│    1    │  'bencode.encode() [utf8] ⨉ 10000'  │ '7,023' │ 142387.93446363122 │ '±2.26%' │   703   │
│    2    │ 'bencode.encode() [ascii] ⨉ 10000'  │ '7,672' │ 130327.47463633618 │ '±1.45%' │   768   │
│    3    │ 'bencode.encode() [binary] ⨉ 10000' │ '7,639' │ 130892.13633412468 │ '±1.32%' │   764   │
│    4    │ 'bencode.decode() [buffer] ⨉ 10000' │ '7,523' │ 132913.91433472652 │ '±2.12%' │   753   │
│    5    │  'bencode.decode() [utf8] ⨉ 10000'  │ '7,518' │ 133007.17764712393 │ '±1.22%' │   752   │
│    6    │ 'bencode.decode() [ascii] ⨉ 10000'  │ '6,617' │ 151124.20331315332 │ '±2.06%' │   662   │
│    7    │ 'bencode.decode() [binary] ⨉ 10000' │ '5,066' │ 197371.98131794526 │ '±2.27%' │   507   │
└─────────┴─────────────────────────────────────┴─────────┴────────────────────┴──────────┴─────────┘

@socket-security
Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
tinybench 2.5.0 None +0 39 kB aslemammad

🚮 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