Kikobeats / js-mythbusters

:ghost: STHAP js, where is my perf?
https://mythbusters.js.org
MIT License
632 stars 68 forks source link

setImmediate vs setTimeout vs process.nextTick #69

Closed Kikobeats closed 6 years ago

Kikobeats commented 6 years ago
   ┌───────────────────────┐
┌─>│        timers         │
│  └──────────┬────────────┘
│  ┌──────────┴────────────┐
│  │     I/O callbacks     │
│  └──────────┬────────────┘
│  ┌──────────┴────────────┐
│  │     idle, prepare     │
│  └──────────┬────────────┘      ┌───────────────┐
│  ┌──────────┴────────────┐      │   incoming:   │
│  │         poll          │<─────┤  connections, │
│  └──────────┬────────────┘      │   data, etc.  │
│  ┌──────────┴────────────┐      └───────────────┘
│  │        check          │
│  └──────────┬────────────┘
│  ┌──────────┴────────────┐
└──┤    close callbacks    │
   └───────────────────────┘
'use strict'

var bench = require('fastbench')

var run = bench([
  function benchSetImmediate (done) {
    setImmediate(done)
  },
  function benchNextTick (done) {
    process.nextTick(done)
  }
], 1024 * 1024)

// run them two times
run(run)

Considerations on browser side

Kikobeats commented 6 years ago

Related: https://github.com/jamiebuilds/tickedoff