ES5 "use strict" Performance

JavaScript performance comparison

Test case created by Jason Miller

Info

What is the performance different for calling a function that has opted in to ES5 Strict Mode?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var baz = "bat";
   
    function normal() {
      return Math.random() * (arguments[0] || 1) + baz;
    }
   
    var normalClosure = (function() {
      "use strict";
      var foo = "bar";
      return function() {
        return Math.random() * (arguments[0] || 1) + foo;
      };
    }());
   
    function strict() {
      "use strict";
      return Math.random() * (arguments[0] || 1) + baz;
    }
   
    var strictClosure = (function() {
      "use strict";
      var foo = "bar";
      return function() {
        return Math.random() * (arguments[0] || 1) + foo;
      };
    }());
   
    var strictInStrictClosure = (function() {
      "use strict";
      var foo = "bar";
      return function() {
        "use strict";
        return Math.random() * (arguments[0] || 1) + foo;
      };
    }());
   
   
    // Warm up the JIT:
    normal();
    normalClosure();
    strict();
    strictClosure();
    strictInStrictClosure();
   
};
</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
Normal
normal();
normal(10);
pending…
Normal Closure
normalClosure();
normalClosure(10);
pending…
Strict
strict();
strict(10);
pending…
Strict Closure
strictClosure();
strictClosure(10);
pending…
Strict In Strict Closure
strictInStrictClosure();
strictInStrictClosure(10);
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