JavaScript performance comparison

Test case created by Felipe


Verifies if adding a string to a number, is faster when the string is of a primitive string type, or a String object.

Preparation code

str1 + str3 = <div id="id1"></div><br>
str2 + str3 = <div id="id2"></div>
Benchmark.prototype.setup = function() {
        var str1 = "Hello";
        var str2 = new String("Hello");
        var str3 = new String(" there");
        var i = "(idle)",
            k = "(idle)";

Benchmark.prototype.teardown = function() {
    var x = document.getElementById("id1"); x.innerHTML = i;
    var y = document.getElementById("id2"); y.innerHTML = k;

Preparation code output

str1 + str3 =

str2 + str3 =

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Primitive and number
  var i = str1 + 10;
Object and number
  var k = str2 + 10;

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment