Properties vs. Indices
JavaScript performance comparison
Info
Check what is faster: Properties or indices?
Preparation code
<script>
Benchmark.prototype.setup = function() {
var playerObj = {
pos: {
x: 0,
y: 0
}
};
var Point = function(x, y) {
this.x = x;
this.y = y;
};
var playerObjWithConstructor = {
pos: new Point(0, 0)
};
var playerArray = {
pos: [0, 0]
}
var tmpStorage = 0,
POS_X = 0,
POS_Y = 1;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Object with Properties |
|
pending… |
Array with Indices |
|
pending… |
Array with Indices and Constants |
|
pending… |
Object with Properties and a Constructor |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments