how slow is eval: not retarded edition
JavaScript performance comparison
Info
this is http://jsperf.com/how-slow-is-eval except not retarded
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.
| Test | Ops/sec | |
|---|---|---|
running it directly |
|
pending… |
evaling the already compiled function |
|
pending… |
evaling the whole thing |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments