Polymorphic Vars

JavaScript performance comparison

Test case created by Joshua Peek

Preparation code

<script>
  function shared() {
   var result, s;
   result = [];
 
   s = "";
   if (s == "") {
    result.push(s)
   }
 
   s = "foo"
   if (s == "foo") {
    result.push(s)
   }
 
   s = "bar"
   if (s == "bar") {
    result.push(s)
   }
 
   s = "baz"
   if (s == "baz") {
    result.push(s)
   }
 
   return result;
  }
 
  function separate() {
   var result, s1, s2, s3, s4;
   result = []
 
   s1 = "";
   if (s1 == "") {
    result.push(s1)
   }
 
   s2 = "foo"
   if (s2 == "foo") {
    result.push(s2)
   }
 
   s3 = "bar"
   if (s3 == "bar") {
    result.push(s3)
   }
 
   s4 = "baz"
   if (s4 == "baz") {
    result.push(s4)
   }
 
   return result;
  }
</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
Shared
shared()
pending…
Separate
separate()
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment