sparse arrays vs objects
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
window.obj = {};
for (var i = 0; i < 25; i++)
obj[i] = Math.random();
window.arr = [];
for (var i = 0; i < 25; i++)
arr[i] = Math.random();
window.items1=[];
items1 = [
['James Bond', 8, 40,'James Bond2', 82, 402],
['Superman', 9999, 36,'Superman2', 99992, 362]
];
window.items2=[];
items2 = [{
Name: 'James Bond', strength: 8,
coolness: 40,
Name2: 'James Bond2', strength2: 82,
coolness2: 402
}, {
Name: 'Superman', strength: 9999,
coolness: 36,
Name2: 'Superman2', strength2: 99992,
coolness2: 362
}];
var item1=items1[1];
var item2=items2[1];
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
array get a |
|
pending… |
object get b |
|
pending… |
object get |
|
pending… |
array get |
|
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 Bergi
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
0 comments