Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Last active May 17, 2024 17:50
Show Gist options
  • Save billywhizz/ece1daa5317adab8256a118a12717512 to your computer and use it in GitHub Desktop.
Save billywhizz/ece1daa5317adab8256a118a12717512 to your computer and use it in GitHub Desktop.
JS Runtime Task Running MicroBench

This is a simple benchmark to compare runtime overhead when running multiple, sequential, non-JS tasks from package.json.

https://x.com/justjs14/status/1791518402776863117

In order to run you will need to clone this gist to a directory that has no package.json or deno.json in the ancestor directory tree

cd /tmp && git clone https://gist.github.com/ece1daa5317adab8256a118a12717512.git

you need to have hyperfine, npm, deno, bun and node 22 installed as this test was created to see the effect of the new node run cli command.

in order to run the test

hyperfine "deno task foo" "bun run foo" "npm run foo" "node --run=foo" 2>/dev/null

if you want to run on your setup feel free to post your results and your environment/machine details in the comments below.

{
"name": "foo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"foo": "/bin/ls -lah && /bin/ls -lah && /bin/ls -lah"
},
"author": "",
"license": "ISC"
}
@billywhizz
Copy link
Author

  • CPU Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
  • OS Linux 6.5.0-28-generic #29~22.04.1-Ubuntu
  • node v22.2.0
  • deno 1.43.3 (release, x86_64-unknown-linux-gnu)
  • bun 1.1.8
  • npm 10.2.4
hyperfine "deno task foo" "bun run foo" "npm run foo" "node --run=foo" 2>/dev/null
Benchmark 1: deno task foo
  Time (mean ± σ):      11.0 ms ±   0.2 ms    [User: 5.8 ms, System: 4.9 ms]
  Range (min … max):    10.4 ms …  12.0 ms    231 runs
 
Benchmark 2: bun run foo
  Time (mean ± σ):       9.8 ms ±   0.2 ms    [User: 5.0 ms, System: 4.8 ms]
  Range (min … max):     9.5 ms …  11.5 ms    252 runs
 
Benchmark 3: npm run foo
  Time (mean ± σ):     126.8 ms ±   1.2 ms    [User: 113.9 ms, System: 22.4 ms]
  Range (min … max):   125.5 ms … 131.5 ms    22 runs
 
Benchmark 4: node --run=foo
  Time (mean ± σ):       8.8 ms ±   0.2 ms    [User: 5.6 ms, System: 3.0 ms]
  Range (min … max):     8.5 ms …   9.8 ms    277 runs
 
Summary
  'node --run=foo' ran
    1.12 ± 0.03 times faster than 'bun run foo'
    1.26 ± 0.03 times faster than 'deno task foo'
   14.48 ± 0.29 times faster than 'npm run foo'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment