Array shuffle comparator

JavaScript performance comparison

Test case created by marlanga

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for (var i = 0; i < 100000; i++) {
    arr[i] = i;
  }
  Array.prototype.mezclar = function() {
    var n = this.length;
    while (n--) {
      var i = Math.floor(n * Math.random());
      var tmp = this[i];
      this[i] = this[n];
      this[n] = tmp;
  
    }
    return this;
  }
  
  var mezclar2 = function(arr) {
      for (var i, tmp, n = arr.length; n; i = Math.floor(Math.random() * n), tmp = arr[--n], arr[n] = arr[i], arr[i] = tmp);
      return arr;
      }
      
      
      
  Array.prototype.mezclar3 = function() {
    for (var i, tmp, n = this.length; n--; i = Math.floor(Math.random() * n), tmp = this[i], this[i] = this[n], this[n] = tmp);
    return this;
  }

};
</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
marlanga
arr.mezclar();
pending…
emprear
arr = mezclar2(arr);
pending…
m+e
arr.mezclar3();
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