chrome-sorting

JavaScript performance comparison

Test case created by

Preparation code

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.2.1/lodash.js"></script>
<script>
  var lodash = _.noConflict();
</script>
      
<script>
Benchmark.prototype.setup = function() {
   var _ = window.lodash;
  var as1 = [], as2 = [];
  var a1 = [], a2 = [];
  var ar1 = [], ar2 = [];
  var i, j, s = [], r;
  var size = 800;
  
   for ( i = 0; i < size; i = i + 1  ) {
  
              for ( j = 0; j < 12 ; j = j + 1 ) {
  
                  r = _.random ( 0, 255 );
  
                  s [ j ] = String.fromCharCode ( r );
              }
  
              as1 [ i ] = s.join('');
              a1 [ i ] = s.join('');
          }
  
          as1.sort();
          as2 = _.cloneDeep ( as1 );
          a2 = _.cloneDeep ( a1 );
   
          ar1 = as1.reverse();
          ar2 = _.cloneDeep ( ar1 );

};
</script>

Preparation code output

<script> var lodash = _.noConflict(); </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
sorted
for ( i = 0 ; i < size; i ++ ) {
   
   x1 [ i ] = as1 [ i ];
   x2 [ i ] = as2 [ i ];
}

x1.sort();
x2.sort();

for ( i = 0 ; i < size ; i ++ )
{
   if ( x1 [ i ] !== x2 [ i ] ) {
 
      break;
   }
}
pending…
reverse sorted
for ( i = 0 ; i < size; i ++ ) {
   
   x1 [ i ] = ar1 [ i ];
   x2 [ i ] = ar2 [ i ];
}

x1.sort();
x2.sort();

for ( i = 0 ; i < size ; i ++ )
{
   if ( x1 [ i ] !== x2 [ i ] ) {
 
      break;
   }
}
pending…
random
for ( i = 0 ; i < size; i ++ ) {
   
   x1 [ i ] = a1 [ i ];
   x2 [ i ] = a2 [ i ];
}

x1.sort();
x2.sort();

for ( i = 0 ; i < size ; i ++ )
{
   if ( x1 [ i ] !== x2 [ i ] ) {
 
      break;
   }
}
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