chrome-sorting-numbers

JavaScript performance comparison

Test case created

Preparation code

<script src="//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, r;
    var size = 1000;
    var x1 = [], x2 = [];
    var done = [];
     for ( i = 0; i < 32000; i++) {
               
                    done [ i ] = 0;
             }
     for ( i = 0; i < size ;  ) {
           
                r = _.random ( 0, 31999 );
           
                if ( done [ r ] === 0 ) {
                        as1 [ i ] = r;
                        a1 [ i ] = r;
                        done [ r ] = 1;
                        i = i + 1;
               }        
        }
           
            as1.sort();
            as2 = _.cloneDeep ( as1 );
            a2 = _.cloneDeep ( a1 );
     
            ar1 = as1.reverse();
            ar2 = _.cloneDeep ( ar1 );
};
</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
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. Here’s a list of current revisions for this page:

0 comments

Add a comment