hash

JavaScript performance comparison

Test case created by Jim Willhite

Info

Comparing an array, string and object based hash

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var id1 = 'x0000000001';
    var id2 = 'p0000000001';
    var id3 = 'f0000000001';
    var id4 = 'y0000000001';
   
    var string_hash = "a00000000021,b00000000021,c00000000021,d00000000021,e00000000021,f00000000021,g00000000021,h00000000021,i00000000021,j00000000021,k00000000021,l00000000021,b00000000021,n00000000021,o00000000021,p00000000021,q00000000021,a0000000001,b0000000001,c0000000001,d0000000001,e0000000001,f0000000001,g0000000001,h0000000001,i0000000001,j0000000001,k0000000001,l0000000001,b0000000001,n0000000001,o0000000001,p0000000001,q0000000001";
   
    var array_hash = ['a00000000021','b00000000021','c00000000021','d00000000021','e00000000021','f00000000021','g00000000021','h00000000021','i00000000021','j00000000021','k00000000021','l00000000021','b00000000021','n00000000021','o00000000021','p00000000021','q00000000021','a0000000001','b0000000001','c0000000001','d0000000001','e0000000001','f0000000001','g0000000001','h0000000001','i0000000001','j0000000001','k0000000001','l0000000001','b0000000001','n0000000001','o0000000001','p0000000001','q0000000001'];
   
    var object_hash = {'a00000000021': 1,'b00000000021': 1,'c00000000021': 1,'d00000000021': 1,'e00000000021': 1,'f00000000021': 1,'g00000000021': 1,'h00000000021': 1,'i00000000021': 1,'j00000000021': 1,'k00000000021': 1,'l00000000021': 1,'b00000000021': 1,'n00000000021': 1,'o00000000021': 1,'p00000000021': 1,'q00000000021': 1,'a0000000001': 1,'b0000000001': 1,'c0000000001': 1,'d0000000001': 1,'e0000000001': 1,'f0000000001': 1,'g0000000001': 1,'h0000000001': 1,'i0000000001': 1,'j0000000001': 1,'k0000000001': 1,'l0000000001': 1,'b0000000001': 1,'n0000000001': 1,'o0000000001': 1,'p0000000001': 1,'q0000000001': 1};
   
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
string_hash
a = string_hash.indexOf(id1);
b = string_hash.indexOf(id2);
c = string_hash.indexOf(id3);
d = string_hash.indexOf(id4);
pending…
array_hash
a = array_hash.indexOf(id1);
b = array_hash.indexOf(id2);
c = array_hash.indexOf(id3);
d = array_hash.indexOf(id4);
pending…
object_hash
a = object_hash[id1];
b = object_hash[id2];
c = object_hash[id3];
d = object_hash[id4];
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