low level optimisation

JavaScript performance comparison

Test case created by vincent piel

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
              var spliceOne = function(arr, index) {
                var len=arr.length, indPlusOne=0;
                if (!len) { return }
                while (index<len) { indPlusOne =index+1; arr[index] = arr[indPlusOne]; index=indPlusOne }
                arr.length--;
               };
   
              var spliceOne2 = function(arr, index) {
                var len=arr.length;
                if (!len) { return }
                while (index<len) {  arr[index] = arr[index+1]; index++ }
                arr.length--;
               };
   
    var arr= [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22];
   
};
</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
first 'optimzed' version of spliceOne
spliceOne(arr, 10);
pending…
second, less optimzed version of spliceOne
spliceOne2(arr,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