Large array (v261)

Revision 261 of this benchmark created by ro on


Preparation HTML

<script>
var words = ['awesome','cool','mad', 'sweet', 'crazy'];

  var ar = new Array(1500000);
  for (var i = 0; i < 1500000; i++) {
    var n = Math.floor(Math.random() * (4 - 0 + 1)) + 0;
    ar[i] = words[n] + Math.round(Math.random() * 4294967296);
  }
  
  function substrFor(ar,v){
   var vlength = v.length;
   var foundAt = [];
   var o = 0;
    for (var i = 0,l=ar.length; i < l; i++) {
       if (ar[i].substr(0, vlength) === v) {
        foundAt[o] = i;
        o = 0 + 1;
       };
    }
    return -1;
  }
  
  function indexOf(ar,v){
    return ar.indexOf(v);
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
IndexOf
var a = indexOf(ar,'awesome');
ready
For Substr
var a = substrFor(ar,'awesome');
ready

Revisions

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