object keys vs for loop
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function Panda(){}
Panda.prototype.eats = "bamboo";
Panda.prototype.climbs = "very small rocks";
Panda.prototype.lives_in = "China";
var p = new Panda(),
o = {};
for (var i = 0, len = 1000; i < len; i += 1) {
o[i] = i * 2;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Object.keys (short) |
|
pending… |
For-in (short) |
|
pending… |
Object.keys (long) |
|
pending… |
For-in (long) |
|
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 John Cockrell
- Revision 2: published by Klimashkin
0 comments