Last active
August 30, 2019 17:06
-
-
Save ra100/dea6c62fde2dc98e30c6b6c5602b7499 to your computer and use it in GitHub Desktop.
Benchmark on different node.js version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Benchmark = require('benchmark') | |
const R = require('ramda') | |
const map = require('lodash.map') | |
const defarrow = array => () => { | |
const a = item => item + 1 | |
return array.map(a) | |
} | |
const forloop = array => () => { | |
const out = [] | |
for (var i = 0; i < array.length; i++) { | |
out.push(array[i] + 1) | |
} | |
return out | |
} | |
const ramda = array => () => { | |
const a = item => item + 1 | |
return R.map(a, array) | |
} | |
const lodash = array => () => { | |
const a = item => item + 1 | |
return map(array, a) | |
} | |
const out = [[], [], [], []] | |
const scenario = (array, size) => { | |
suite = new Benchmark.Suite() | |
suite | |
.add('map', defarrow(array)) | |
.add('for', forloop(array)) | |
.add('ramda', ramda(array)) | |
.add('lodash', ramda(array)) | |
// .on('cycle', event => { | |
// console.info(String(event.target), event.target.hz) | |
// }) | |
.on('complete', () => { | |
const results = suite.map(s => Math.floor(s.hz * size)) | |
for (var k = 0; k < results.length; k++) { | |
out[k].push(results[k]) | |
} | |
}) | |
.run() | |
} | |
for (var i = 1; i <= 10000000; i = i * 10) { | |
var array = Array(i) | |
.fill(0) | |
.map((a, i) => i) | |
scenario(array, i) | |
} | |
const version = process.version | |
const tests = ['map', 'for', 'ramda', 'lodash'] | |
for (var j = 0; j < out.length; j++) { | |
console.log(version + '-' + tests[j] + ' ' + out[j].map(String).join(' ')) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export NODE_ENV=production | |
function benchmark { | |
echo $NODE_ENV | |
nvm use "$1" | |
rm -rf node_modules | |
npm i | |
node for-map.js >> results.txt | |
} | |
benchmark 4 | |
benchmark 6 | |
benchmark 8 | |
benchmark 10 | |
benchmark 11 | |
benchmark 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "nodebench", | |
"version": "1.0.0", | |
"description": "", | |
"main": "bench.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"benchmark": "^2.1.4", | |
"lodash.map": "^4.6.0", | |
"ramda": "^0.26.1" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v4.9.1-map 4561426 11636905 14757111 14967702 14855885 15092053 14269126 14529992 | |
v4.9.1-for 28192452 154308614 159897884 156444372 147897936 161935874 60580287 46947177 | |
v4.9.1-ramda 1364886 12646556 63598917 105809736 114432908 121314576 85808626 88918311 | |
v4.9.1-lodash 1433139 12244577 62247120 106658581 114826702 122422422 85660291 89438147 | |
v6.17.1-map 1825905 2558404 2562730 2519030 2537938 1699887 1615711 1654766 | |
v6.17.1-for 24173582 150449303 127030555 147609580 136429540 91872918 52736659 47999330 | |
v6.17.1-ramda 1844130 14192082 57524221 100708863 108448791 74321710 82854332 89513928 | |
v6.17.1-lodash 1754818 14951969 46567406 100050350 106729023 77208854 82793717 88110875 | |
v8.16.0-map 10592705 39758890 61004355 65345990 66924220 6972618 7096787 6943962 | |
v8.16.0-for 26136759 157199470 190592357 179679343 195569873 70323662 50408978 47773108 | |
v8.16.0-ramda 4119820 30974665 87909397 109592354 109293693 75032230 84038700 85000426 | |
v8.16.0-lodash 4150525 30887155 88561622 108351050 112561074 76364194 83915050 84479824 | |
v10.16.0-map 78674873 233948263 331257468 315010060 307676801 6728500 7266480 7262032 | |
v10.16.0-for 29399076 200397750 189353154 183924914 206985910 75597432 52660217 47861125 | |
v10.16.0-ramda 5222369 34861262 80971341 101105658 101599904 74783027 78568673 83070235 | |
v10.16.0-lodash 5355665 35026214 81149594 102370639 102848546 73697117 78357844 82182737 | |
v11.15.0-map 73470116 231347203 330741022 339956941 333480385 7077673 7142953 7135761 | |
v11.15.0-for 30084280 199596395 188902182 184263909 205331778 75056980 52814763 49274780 | |
v11.15.0-ramda 5105641 35054915 79216615 98892510 99963461 73693757 78364305 83450937 | |
v11.15.0-lodash 5200081 34871951 80379704 99589989 99988025 73242399 78083713 82652017 | |
v12.6.0-map 43871274 240492153 395656850 419830986 419339616 48864443 49891941 48719227 | |
v12.6.0-for 25988625 196292477 198940903 182413437 199190785 75041314 50383613 40974428 | |
v12.6.0-ramda 7917015 44291841 80609864 95004290 97505835 80127842 77331710 77257113 | |
v12.6.0-lodash 8052335 44159300 80245829 94906948 95923766 78466215 76837915 78091185 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment