Created
May 13, 2016 21:07
-
-
Save nodech/dc46a10688d896c1a201b3175abd5a90 to your computer and use it in GitHub Desktop.
Test benchmarks
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
var o = {}; | |
for (var i = 0; i < 100; i++) { | |
o['key' + i] = 'value ' + i; | |
} | |
exports.compare = { | |
//#3 | |
"for(var .. in ..)" : function () { | |
for(var key in o) { | |
test(key, o[key]); | |
} | |
}, | |
//#4 | |
"for(var .. in ..) OwnProperty" : function () { | |
for(var key in o) { | |
if (o.hasOwnProperty(key)) { | |
test(key, o[key]); | |
} | |
} | |
}, | |
// #1 | |
"Object.keys" : function () { | |
var keys = Object.keys(o); | |
for(var i = 0; i < keys.length; i++) { | |
test(keys[i], o[keys[i]]) | |
} | |
}, | |
// #2 | |
"Object.keys ForEach" : function () { | |
var keys = Object.keys(o); | |
keys.forEach(function (key) { | |
test(key, o[key]); | |
}) | |
}, | |
}; | |
function test(key, val) {} | |
require("bench").runMain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment