Get from object vs array
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var obj = {1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,10:10};
var arr = new Array(1,2,3,4,5,6,7,8,9,10);
function getFromObject(){
for(var i = 0; i < 10; i++){
for(var i = 0; i < arr.length; i++){
if(i == arr[i]){
var val = arr[i];
break;
}
}
}
}
function getFromArray(){
for(var i = 0; i < 10; i++){
var val = obj[i];
}
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Get from object |
|
pending… |
Get from array |
|
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 Jason Venable
- Revision 2: published
0 comments