Skip to content

Instantly share code, notes, and snippets.

@dylanpyle
Last active September 9, 2016 22:20
Show Gist options
  • Save dylanpyle/4a7c15f1581acebe76d9d739aec7594a to your computer and use it in GitHub Desktop.
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
$ 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
'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