Last active
August 29, 2015 14:08
-
-
Save jjoos/ae4b3e5d0fbd1d25e41f to your computer and use it in GitHub Desktop.
Avoiding built-in object look ups.
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
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