specify costs

JavaScript performance comparison

Test case created and last updated

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var ns = {};
   
    function first(x) {
      return x;
    }
   
    function second(x) {
      return x;
    }
   
    function foo(x) {
      x.first = first;
      x.second = second;
      return x;
    }
   
    function bar(x) {
      x.first = function(y) {
        return y;
      }
      x.second = function(y) {
        return y;
      }
      return x;
    }
   
    function baz(x) {
      if(!ns.first) {
        ns.first = function(y) {
          return y;
        }
      }
      x.first = ns.first;
      if(!ns.second) {
        ns.second = function(y) {
          return y;
        }
      }
      x.second = ns.second;
      x.locals = {
        a: 1,
        b: 2
      };
      return x;
    }
};
</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
no fn creation
foo({x:1,y:2});
pending…
fn creation
bar({x:1,y:2});
pending…
fn cache + locals lookup
baz({x:1,y:2})
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