Function In Loop

JavaScript performance comparison

Test case created by Aaron Marasco

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function rand(from, to) {
      from = from || 0;
      to = to || 255;
      return Math.floor(Math.random() * (to - from + 1) + from);
    }
   
    var arr = [];
    for (var i = 0; i < 10; i++) {
      arr.push([rand(), rand(), rand()]);
    }
   
    function arrtostring(a) {
      return a.join();
    }
};
</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
Use Predefined Function
var ret = arr.map(arrtostring);
pending…
Create Function
var ret = arr.map(function(a) {
  return a.join();
});
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment