Find max in Float32Array

JavaScript performance comparison

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] = i;
   
    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 unknown unknown
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. Here’s a list of current revisions for this page:

0 comments

Add a comment