how slow is eval: not retarded edition

JavaScript performance comparison

Test case created by crazy ojifewojifewojifewojifew

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function superslow(r) {
    var tot=0;
    for(var i=0;i<10000+r;++i) {
      var x=Math.random();
      if(x<0.5) {
        tot+=Math.sin(x);
      } else {
        tot+=Math.cos(x);
      }
    }
    return Math.sin(tot);
  }
  var superslowstring="function superslow(r){var tot=0;for(var i=0;i<10000+r;++i){var x=Math.random();if(x<0.5){tot+=Math.sin(x);}else{tot+=Math.cos(x);}}return Math.sin(tot);} superslow(Math.random());";

};
</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
running it directly
var x = superslow(Math.random());
pending…
evaling the already compiled function
var x = eval("superslow(Math.random());");
pending…
evaling the whole thing
eval(superslowstring);
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