Skip to content

Instantly share code, notes, and snippets.

@jjoos
Last active August 29, 2015 14:08
Show Gist options
  • Save jjoos/ae4b3e5d0fbd1d25e41f to your computer and use it in GitHub Desktop.
Save jjoos/ae4b3e5d0fbd1d25e41f to your computer and use it in GitHub Desktop.
Avoiding built-in object look ups.
var start = new Date().getTime();
var sum = 0;
for (i = 0; i < 5000000; ++i) {
sum += Math.sin(Math.random());
}
var end = new Date().getTime();
var time = end - start;
console.info('Builtin object lookup: execution time: ' + time, sum);
sin = Math.sin;
var start = new Date().getTime();
var sum = 0;
for (i = 0; i < 5000000; ++i) {
sum += sin(Math.random());
}
var end = new Date().getTime();
var time = end - start;
console.info('Local variable: execution time: ' + time, sum);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment