Last active
September 9, 2016 22:20
-
-
Save dylanpyle/4a7c15f1581acebe76d9d739aec7594a to your computer and use it in GitHub Desktop.
`fn.bind` is ~25x slower than arrow functions. who knew? not me at least
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
$ ITER=1000000 node out.js | |
Ran with .bind in 1691 | |
Ran with arrow function in 75 | |
$ ITER=10000000 node out.js | |
Ran with .bind in 16719 | |
Ran with arrow function in 734 |
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
'use strict'; | |
const ITER = parseInt(process.env.ITER || 10000); | |
const a = function(val){ return val + 1; }; | |
const aStart = Date.now(); | |
for (let i = 0; i < ITER; i++) { | |
const fn = a.bind(null, 1); | |
fn(); | |
} | |
console.log('Ran with .bind in ', (Date.now() - aStart)); | |
const bStart = Date.now(); | |
for (let i = 0; i < ITER; i++) { | |
const fn = () => { return a(1); }; | |
fn(); | |
} | |
console.log('Ran with arrow function in ', (Date.now() - bStart)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment