Compiler Optimization

JavaScript performance comparison

Test case created by niftymonkey

Info

This test is meant to illustrate that there is a lot of work the compiler does to optimize the data structures when it sees that your function is consistently being called with the same types of values.

Moral of the story is, don't mix your types in your function usage.

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Just Numbers
function add(a, b) {
  return a + b;
}

for(var i = 0; i<100000; i++) {
  add(1, 2);
  add(3, 4);
  add(5, 6);
}
pending…
Just Strings
function add(a, b) {
  return a + b;
}

for(var i = 0; i<100000; i++) {
  add("a", "b");
  add("c", "d");
  add("e", "f");
}
pending…
Numbers AND Strings
function add(a, b) {
  return a + b;
}

for(var i = 0; i<100000; i++) {
  add(1, 2);
  add(3, 4);
  add("A", "B");
}
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