Add a property to an array
JavaScript performance comparison
Preparation code
<script>
function plainArray() {
var a = [];
for (var i = 0; i < 10000; i++) {
a[i] = i;
}
var sum = 0;
for (var i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
function arrayWithProperty() {
var a = [];
a.foo = 123;
for (var i = 0; i < 10000; i++) {
a[i] = i;
}
var sum = 0;
for (var i = 0; i < a.length; i++) {
sum += a[i];
}
return sum;
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Plain array |
|
pending… |
Array with property |
|
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 Erik Corry
- Revision 2: published
- Revision 3: published by Erik Corry
0 comments