Skip to content

Instantly share code, notes, and snippets.

@weyoss
Last active February 19, 2024 16:08
Show Gist options
  • Save weyoss/24f9ecbda175d943a48cb7ec38bde821 to your computer and use it in GitHub Desktop.
Save weyoss/24f9ecbda175d943a48cb7ec38bde821 to your computer and use it in GitHub Desktop.
Callback vs Promise vs Async/Await
Callback vs Promise vs Async/Await benchmarks
Benchmark Files
https://github.com/petkaantonov/bluebird/tree/master/benchmark
Platform Info
Linux 5.13.0-40-generic x64
Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz × 4
Summary
In terms of performance and memory usage, there is no alternative to callbacks.
Promise and async/await are slower and use more resources.
ls ./doxbee-sequential/*.js | sed -e 's|\.js||' | xargs node ./performance.js --p 1 --t 1 --n 10000
results for 10000 parallel executions, 1 ms per I/O op
file time(ms) memory(MB)
callbacks-baseline 329 24.58
callbacks-caolan-async-waterfall 420 50.55
callbacks-suguru03-neo-async-waterfall 426 41.49
promises-bluebird-generator 499 42.61
promises-native-async-await 558 56.47
promises-bluebird 570 50.09
promises-ecmascript6-native 614 67.87
promises-lvivski-davy 622 91.29
promises-cujojs-when 705 67.07
promises-then-promise 782 75.79
generators-tj-co 804 59.77
promises-tildeio-rsvp 911 91.99
promises-calvinmetcalf-lie 1099 141.34
promises-dfilatov-vow 1445 141.14
promises-obvious-kew 1471 104.65
observables-pozadi-kefir 1499 146.91
streamline-generators 1540 77.86
promises-medikoo-deferred 1758 132.80
streamline-callbacks 2190 102.14
observables-Reactive-Extensions-RxJS 2732 218.70
promises-kriskowal-q 5838 359.06
observables-caolan-highland 6688 488.01
observables-baconjs-bacon.js 10233 761.92
Platform info:
Linux 5.13.0-40-generic x64
Node.JS 16.14.0
V8 9.4.146.24-node.20
Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz × 4
ls ./madeup-parallel/*.js | sed -e 's|\.js||' | xargs node ./performance.js --p 25 --t 1 --n 10000
results for 10000 parallel executions, 1 ms per I/O op
file time(ms) memory(MB)
callbacks-baseline 624 82.00
callbacks-suguru03-neo-async-parallel 719 88.20
promises-bluebird 1037 105.51
promises-lvivski-davy 1099 156.89
callbacks-caolan-async-parallel 1141 116.48
promises-bluebird-generator 1198 106.91
promises-cujojs-when 1391 157.09
promises-ecmascript6-native 2280 212.14
generators-tj-co 2289 225.09
promises-native-async-await 2346 218.36
promises-then-promise 2358 235.82
promises-calvinmetcalf-lie 2927 330.71
promises-tildeio-rsvp 3006 315.84
promises-medikoo-deferred 3859 356.98
promises-dfilatov-vow 5261 476.34
promises-obvious-kew 5971 657.50
streamline-generators 14209 857.03
streamline-callbacks 20183 1066.83
Platform info:
Linux 5.13.0-40-generic x64
Node.JS 16.14.0
V8 9.4.146.24-node.20
Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz × 4
@iambumblehead
Copy link

github doesn't give me a place to "thumbs up" your reply, however, "thumbs up" :)

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