Last active
October 30, 2015 01:44
-
-
Save trusktr/d7e7a9d1161dd5a7971e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Test 1 - for..in with hasOwnProperty check. | |
*/ | |
var counter = 0 | |
var i | |
var p | |
var start = performance.now() | |
for (i=0; i<1000; i+=1) { | |
for (p in window) { | |
if (window.hasOwnProperty(p)) {} | |
} | |
} | |
var end = performance.now() | |
console.log('Test 1', end - start) | |
/* | |
* Test 2 - for..in with propertyIsEnumerable check. | |
*/ | |
start = performance.now() | |
for (i=0; i<1000; i+=1) { | |
for (p in window) { | |
if (window.propertyIsEnumerable(p)) {} | |
} | |
} | |
end = performance.now() | |
console.log('Test 2', end - start) | |
/* | |
* Test 3 - for loop on Object.getOwnPropertyNames | |
*/ | |
var j | |
var l | |
start = performance.now() | |
var props = Object.getOwnPropertyNames(window) | |
l = props.length | |
for (i=0; i<1000; i+=1) { | |
for (j=0; j<l; j+=1) { | |
if (window.propertyIsEnumerable[props[j]]) {} | |
} | |
} | |
end = performance.now() | |
console.log('Test 3', end - start) | |
/* | |
* Test 4 - for loop on Object.keys | |
*/ | |
start = performance.now() | |
var props = Object.keys(window) | |
l = props.length | |
for (i=0; i<1000; i+=1) { | |
for (j=0; j<l; j+=1) {} | |
} | |
end = performance.now() | |
console.log('Test 4', end - start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment