Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7666077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:44:35+00:00 2026-05-31T14:44:35+00:00

I read this article about javasccript performance on string concatenation and scope variable so

  • 0

I read this article about javasccript performance on string concatenation and scope variable so I rewrote some of my code the way it was suggested but the recommended way is MUCH slower. I’m testing using Chrome and IE: similar conclusion.

Basically, I have an object that contains strings and I’m loop through each value to generate HTML. The two ways I’m comparing are doing:

var TheHTML = "";
TheHTML = TheHTML + ...;

and the other way is using an array and join

TheHTML[i++] = ....;

I have a fiddle here. The code I’m using looks like this:

var ObjectTest = {};

ObjectTest.Key1 = "The Key 1";
ObjectTest.Key2 = "The Key 2";
ObjectTest.Key3 = "The Key 3";
ObjectTest.Key4 = "The Key 4";
ObjectTest.Key5 = "The Key 5";

function TestSpeed() {

    var TheHTML1 = "";
    var THeHTML2 = "";

    var TheStart1 = new Date().getTime();
    for (var TestPerf1 = 0; TestPerf1 < 100000; TestPerf1++) {

        TheHTML1 = "";
        TheHTML1 = TheHTML1 + '<div style="clear:both">' + ObjectTest.Key1 + '</div>';
        TheHTML1 = TheHTML1 + '<div style="clear:both">' + ObjectTest.Key2 + '</div>';
        TheHTML1 = TheHTML1 + '<div style="clear:both">' + ObjectTest.Key3 + '</div>';
        TheHTML1 = TheHTML1 + '<div style="clear:both">' + ObjectTest.Key4 + '</div>';
        TheHTML1 = TheHTML1 + '<div style="clear:both">' + ObjectTest.Key5 + '</div>';
        TheHTML1 = TheHTML1 + '<br><br>';

    }
    document.getElementById('TestOutput1').innerText = new Date().getTime() - TheStart1;
    document.getElementById('Output1').innerHTML = TheHTML1;


    var TheStart2 = new Date().getTime();
    var ObjectTestCopy = ObjectTest;

    for (var TestPerf2 = 0; TestPerf2 < 100000; TestPerf2++) {

        var Test = [];
        var i = 0;

        Test[i++] = '<div style="clear:both">' + ObjectTestCopy.Key1 + '</div>';
        Test[i++] = '<div style="clear:both">' + ObjectTestCopy.Key2 + '</div>';
        Test[i++] = '<div style="clear:both">' + ObjectTestCopy.Key3 + '</div>';
        Test[i++] = '<div style="clear:both">' + ObjectTestCopy.Key4 + '</div>';
        Test[i++] = '<div style="clear:both">' + ObjectTestCopy.Key5 + '</div>';
        Test[i++] = '<br><br>';

        TheHTML2 = Test.join("");
    }
    document.getElementById('TestOutput2').innerText = new Date().getTime() - TheStart2;
    document.getElementById('Output2').innerHTML = TheHTML2;
}

window.onload = function () { TestSpeed(); }

Why is the suggested code slower?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T14:44:36+00:00Added an answer on May 31, 2026 at 2:44 pm

    It helps if you read the ENTIRE article:

    However, browser string optimizations have changed the string concatenation picture.

    Firefox was the first browser to optimize string concatenation. Beginning with version 1.0, the array technique is actually slower than using the plus operator in all cases. Other browsers have also optimized string concatenation, so Safari, Opera, Chrome, and Internet Explorer 8 also show better performance using the plus operator. Internet Explorer prior to version 8 didn’t have such an optimization, and so the array technique is always faster than the plus operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've read this article about authentication library. some of this answer is not satisfy
I have read this article about 400% boost of your website . This is
I have read this article from High Scalability about Stack Overflow and other large
I already read many article about this issue in here, SO. I just want
I read and article talking about moving beyond 960px width for websites. This width
I have read this article about using WMI to change the settings of NICs
I have just read this interesting article about the implementation details for various languages
I read this article about how you can prefix routes in ruby on rails.
I have a silly question. I read this article about std::exception http://www.cplusplus.com/doc/tutorial/exceptions/ On catch
I read this article here that talks about progressive enhancement for javascript and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.