Object.keys-vs-for-in-hasOwnProperty Anonymous Object
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var foo = {
a: "A",
b: "B",
c: "C",
d: "D",
e: "E",
f: "F",
g: "G",
h: "H",
i: "I",
j: "J",
k: "K",
l: "L",
m: "M",
n: "N",
o: "O",
p: "P",
q: "Q",
r: "R",
s: "S",
t: "T",
u: "U",
v: "V",
w: "W",
x: "X",
y: "Y",
z: "Z"
};
var bar = Object.create(foo, {
a: {
value: "aa"
},
b: {
value: "bb"
},
c: {
value: "cc"
},
D: {
value: "dd"
},
E: {
value: "ee"
},
F: {
value: "ff"
},
G: {
value: "gg",
enumerable: true
},
H: {
value: "hh",
enumerable: true
},
I: {
value: "ii",
enumerable: true
}
});
var hasOwn = foo.hasOwnProperty;
var example = [];
var quux = {
G: "gg",
H: "hh",
I: "ii"
};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
for-in-loop/hasOwnProperty |
|
pending… |
Object.keys/for-loop |
|
pending… |
Object.keys/forEach |
|
pending… |
for-in loop |
|
pending… |
Object.keys/for-loop/quux |
|
pending… |
for-in loop/quux |
|
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
- Revision 2: published by Just another JS hacker
- Revision 3: published by Krinkle
- Revision 4: published
- Revision 6: published
- Revision 7: published
0 comments