Object delete vs. array splice vs. array delete
JavaScript performance comparison
Info
Is it faster to remove an item from an array (and thus allow the indices to be renumbered) or delete a property from an object. Also, checking deletion from array, but this does not renumber the indices so may not be preferable.
Preparation code
<script>
var count = 100000;
var deleteInc = 100;
</script>
<script>
Benchmark.prototype.setup = function() {
var someArr = [];
var someObj = {};
for(var i = 0; i < count; i++)
{
someArr[i] = Math.floor(Math.random() * 1000000);
someObj['a' + i] = Math.floor(Math.random() * 1000000);
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Splice |
|
pending… |
Object Delete |
|
pending… |
Array Delete |
|
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
- Revision 3: published by Quentin Brooks
- Revision 4: published
- Revision 5: published
- Revision 6: published by Reuven
- Revision 7: published
- Revision 9: published
0 comments