Large Object Versus Separate Objects (with Manual Look-ups)
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
//For test #1 - Separate Objects
tile = [];
for (x = 0; x <= 256; x++) {
for (y = 0; y <= 256; y++) {
tile[x] = tile[x] || {};
tile[x][y] = "test" + Math.floor(Math.random() * 10);
}
}
monster = [];
for (i = 0; i <= 1000; i++) {
monster[i] = {
x: Math.floor(Math.random() * 256 + 1),
y: Math.floor(Math.random() * 256 + 1)
};
}
//For test #2 - Combined Object
tile2 = [];
for (x = 0; x <= 256; x++) {
for (y = 0; y <= 256; y++) {
tile2[x] = tile[x] || {};
tile2[x][y] = {
tile: "test" + Math.floor(Math.random() * 10),
monsters: []
};
}
}
for (i = 0; i <= 1000; i++) {
tile2[Math.floor(Math.random() * 256 + 1)][Math.floor(Math.random() * 256 + 1)].monsters.push(i);
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Separate Objects |
|
pending… |
Combined Object |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments