binsearch array manipulation patterns

JavaScript performance comparison

Test case created by thrigs

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function insertOneAt(arr, item, index) {
      var tmp1=item, tmp2=item;
      var len = arr.length;
      for (; index<=len; index++) {
         tmp2 = arr[index]
         arr[index]=tmp1;
         tmp1=tmp2;
      } 
  }
  function insertAt(arr, item, index){
       arr.splice(index, 0, item);
  }
  var arr = [];

};

Benchmark.prototype.teardown = function() {
  delete arr;

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Array.splice
insertAt(arr,"Example String",arr.length-1);
insertAt(arr,"Example String",0);
insertAt(arr,"Example String",(arr.length-1)>>>1);
pending…
Custom Insert
insertOneAt(arr,"Example String",arr.length-1);
insertOneAt(arr,"Example String",0);
insertOneAt(arr,"Example String",(arr.length-1)>>>1);
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.

0 Comments