Created
December 13, 2016 15:27
-
-
Save erikmaarten/530f3016f537aeaa31e9ee7ab69ca0ab to your computer and use it in GitHub Desktop.
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 iterations = 1000000; | |
var some_type = true; | |
function isArray(value) { | |
return Object.prototype.toString.call(value) === '[object Array]'; | |
}; | |
var startTime = performance.now(); | |
for (var i = 0; i < iterations; i++) { | |
if (isArray(some_type)) { | |
} | |
} | |
var timeTaken = performance.now() - startTime; | |
console.log('isArray time: ' + Math.round(timeTaken)); | |
function defined(arg) { | |
return arg !== undefined && arg !== null; | |
} | |
startTime = performance.now(); | |
for (var i = 0; i < iterations; i++) { | |
if (!defined(some_type)) { | |
} | |
} | |
var timeTaken = performance.now() - startTime; | |
console.log('defined time: ' + Math.round(timeTaken)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment