object-looping
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var obj = {
a: 1,
b: 2,
c: 3,
d: 4,
f: 5
},
i = 0,
_hasOwnProperty = Object.prototype.hasOwnProperty,
value = null,
keys = Object.keys(obj)
function each (obj, fn) {
for (var key in obj) {
if (_hasOwnProperty.call(obj, key)){
fn.call(obj, key, obj[key])
}
}
}
function each2 (obj, fn) {
var keys = Object.keys(obj)
for (var i=0, key; key = keys[i++]; fn.call(obj, key, obj[key]));
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
for in, if |
|
pending… |
for in, continue |
|
pending… |
Object.keys() |
|
pending… |
Object.keys() cached |
|
pending… |
Keys for; |
|
pending… |
each, for in |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by everywhile
- Revision 2: published by Jonathan Perry
- Revision 3: published by Jean Carlo Emer
- Revision 4: published by Jonathan Perry
0 comments