find-id-in-object-vs-array

JavaScript performance comparison

Test case created by yangqing

Info

rt

Preparation code

<script src="http://underscorejs.org/underscore-min.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var obj =  [{id:'10'}, {id:'11'},{id:'12'},{id:'13'},{id:'14'}]
   
    var obj2 = {
     '10': {id : '10'}
    ,'11': {id : '11'}
    ,'12': {id : '12'}
    ,'13': {id : '13'}
    ,'14': {id : '14'}
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
object
var a = _.find(obj, function(o){return o.id === '10'})
pending…
array
var a = obj2['10']
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment