eval-methods

JavaScript performance comparison

Revision 9 of this test case created

Info

http://moduscreate.com/javascript-performance-tips-tricks/

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var strCode = 'var str="";for(var i=0;i<1000000;i+=1){str+="a";}';
    var b = new Blob([strCode]);
    var url = URL.createObjectURL(b);
    var scope = {hello: true};
   
    function loadBlob(){
        var script = document.createElement("script")
        script.type = "text/javascript";
        if (script.readyState){  //IE
            script.onreadystatechange = function(){
                if (script.readyState == "loaded" ||
                        script.readyState == "complete"){
                    script.onreadystatechange = null;
                    deferred.resolve()
                }
            };
        } else {  //Others
            script.onload = function(){
                deferred.resolve()
            };
        }
        script.src = url;
        document.getElementsByTagName("head")[0].appendChild(script);
    }
};
</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
eval (not wrapped)
(function() {
  eval(strCode);
})();
pending…
new Function
(function() {
  (new Function(strCode))();
})();
pending…
global eval
(function() {
  (0,eval)(strCode);
})();
pending…
no eval
var str="";
for(var i=0;i<1000000;i+=1){str+="a";}
 
pending…
eval (wrapped)
(function() {
  eval('(function(){'+strCode+'})()');
})();
pending…
Blob
// async test
loadBlob();
pending…
Eval Scoped
(function() {
  f = eval('(function(){ return (function(){'+strCode+'}); })()');
  f.call( scope );
})();
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