Find max in Float32Array

JavaScript performance comparison

Revision 2 of this test case created by Kevin Ennis

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var len = 1e2
    , i = 0
    , arr = new Float32Array(len)
    , max
    , loop
    , func;
  
  for ( ; i < len; i++ ) arr[i] = Math.random();
  
  Float32Array.prototype.max = function(){
    var max = -Infinity, i = 0, len = this.length;
    for ( ; i < len; i++ )
      if ( this[i] > max ) max = arr[i];
    return max;
  };

};
</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
Math.max
max = -Infinity;
max = Math.max.apply(Math, arr);
pending…
Raw for loop
loop = -Infinity;
for ( var j = 0, l = arr.length; j < l; j++ )
  if ( arr[j] > loop ) loop = arr[j];
pending…
Abstracted loop (function overhead)
func = -Infinity;
func = arr.max();
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