asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Multiple Response.Writes vs. String Concatenation
By 15 Seconds Discussion List
Rating: 3.3 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Ben Wants to Know:

    I'm getting conflicting opinions on whether it is better to do loads of Response.Writes rather than building up a big string and doing one Response.Write.

    I am now at a stage where all my pages are written using Subs/Functions that utilise Response.Write, I did it this way because I had read/heard that doing loads of strHTML = strHTML + "data" command is very slow and inefficient in VBScript.

    Any views on this? I admit I have done no time tests (v.busy at the moment) but if anyone has i'd be interested in the results.

    Art Says:

    My experience shows that for very long strings, it is *much* faster to do multiple Writes than to concatenate all the strings first.

    Luis Provides:

    I hope Ken Schaefer doesn't mind me publishing this, check out this link:

    http://www.adopenstatic.com/experiments/stringconcantenation.asp

    Tomm Concurs:

    I avoid intermixing straight HTML and asp by writting the *entire* page using multipe response.writes....

    Arnold Challenges:

    A savings of maybe 4%, best vs worst. Useful effort on Ken's part, which has convinced me to apply my optimization time/efforts elsewhere.

    Art Replies:

    Huh? 6187ms vs 47ms is a savings of ~99.2%. What are you referring to?

    My own experience has shown that changing concatenation to multiple Writes can change a page that you have to sit and wait for into a page that loads almost instantly.

    Tomm Find an Exception:

    The only exception to this rule I've found is when you call a sub from a sub...then it may not work as well to write from the called sub. I have timed this type of situation and found concatenation faster in many cases. It's the only exception I've found so far to the general rule of response.writing instead of concatenating. None of these strings tested were over 200-300 lines...

    Anders Does a Test:

    String-concatenation in VBScript has proven to be slow, if not really slow.

    I made a test with a C++ COM object vs. VBScript contatenation. It was a typical XML string concatenation with 1.000 and 10.000 iterations.

    I'm using a lame PII 233Mhz server here (just a little private IIS) for testing.

    1000 iterations:
    C++ COM object: 0,03906 secs.
    VBScript engine: 1,77344 secs.
    VBScript it 45,40 times slower.
    
    10.000 iterations:
    C++ COM object: 0,48047
    VBScript engine: 363,1797
    VBScript it 755,88 times slower.
    

    I know its not likely that you to 10.000 concatenations on a page, but you get the idea. With XML in particular, every *single* concatenation has to be as fast as possible because the extra step involved in using XML/XSL comes with a performace hit.

    You can thus allow yourself the luxury of seperating your code from presentation 100% and get the *same* performance (valid when building strings of HTML using ASP. Response.Writes of HTML directly can't compete, ofcourse!)

    -- Attached ASP Code --

    Option Explicit
    Server.ScriptTimeout = 10000
    
    Dim oCat
    Dim intI
    Dim strXML
    Dim timStart
    
    timStart = timer
    
    '## C++ ENGINE
    Set oCat = CreateObject("StrCat.Catter")
    oCat "<TimerTree>" & vbCrLf
    For intI = 1 To 1000
    oCat "<TimerNode><![CDATA[TestDataTestData" & intI & "]]></TimerNode>" &
    vbCrLf
    Next
    oCat "</TimerTree>" & vbCrLf
    Set oCat = nothing
    Response.Write("Test 1: " & Round(timer - timStart, 5) & "<br>")
    
    timStart = timer
    
    '## VBScript ENGINE
    strXML = "<TimerTree>" & vbCrLf
    For intI = 1 To 1000
    strXML = strXML & "<TimerNode><![CDATA[TestDataTestData" & intI &
    "]]></TimerNode>" & vbCrLf
    Next
    strXML = strXML & "</TimerTree>" & vbCrLf
    
    Response.Write("Test 2: " & Round(timer - timStart, 5) & "<br>")
    

    Ben Wants To Know:

    Anders, care to share your COM object so I can test on the servers here?

    Anders:

    Yes, ofcourse I'll share the C++ component. I haven't programmed it myself, but have given it some thoughts on adding some more functionality to the class. Also, I don't like the name of the component, but that is only nitty gritty stuff which everyone else can live with!

    Here's the link to the site with the original component:
    http://www.4guysfromrolla.com/webtech/092500-1.shtml

    These guys deserve great credit. I've just speeded up my backend (really big Content Management System) by a factor of 3 - 5 depending upon datasizes. Really impressive - extremely impressive, rather. Issues like this makes one wonder if there many other issues like this in ASP!

    I'll keep this list posted if I change anything - and the original author, ofcourse!

    Paul Throws Some XML into the Mix:

    I have looked at this slow string concatenation for number of our applications (server-side XML) and found best solution is to limit the string sizes (because vbs is copying the existing to add the new).

    Try changing the loop structure from a 1X1000 iteration loop to a 10 X 100

    Something like:

    for x=0 to 9
    strXML=""
    For intI = 1 To 100
    strXML = strXML & string_to_add
    Next
    ostr=ostr&strXML
    next
    
    I use this a lot on large XML record assembly and get good results.

    Anders Concludes:

    This is true. I have found too, that when you're converting recordsets into XML, the bottleneck is at the data-source (the DB), not the string-concatenation. This obviously goes for the file-system too. And since we do a lot of recordset -> XML stuff here, the advantage is not so big as I could ask for.

    This conversation string was taken from the 15Seconds ASP Listserv on 3/21/01. If you have an ASP-related question or would like to share some of your knowledge with others, you may join the list by clicking here.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    XCache
    XCache combines dynamic content caching technology with content delivery network (CDN) support options, file compression and a whole lot of manageability features to help e-businesses deliver superior web site performance and reliability. You'll appreciate the administrative ease, your visitors will appreciate increased page delivery speed.
    [Top]
    XCompress
    XCompress works by compressing outgoing text between the Web server and the client. Page response times may improve by a factor of three or more while overall bandwidth use can drop by two thirds or more.

    XCompress runs on Windows 2000 and Windows NT 4.0 and is tightly integrated with Microsoft Internet Information Server (IIS) with MMC and COM interfaces.

    [Top]
    XTune
    XTune 2.0 is the most powerful tuning application for IIS 4 or IIS 5 ever conceived. Indispensable to the enterprise and straightforward, this web tuning tool allows you to configure hidden operating system, network, Active Server Pages and Internet Information Server settings for better performance, without any additional hardware or software.

    This version scans your system more deeply, offering more performance-enhancing recommendations and greater insight into your web architecture. The Performance Wizard guides and teaches you throughout the complete tuning process, so you can learn while making your box run better than ever.

    Purchase here.

    [Top]
    Other Articles
    Aug 25, 2005 - Performance Monitoring in SharePoint Portal Server 2003
    Performance monitoring helps organizations identify performance bottlenecks. The problem is that with so many performance numbers available, how do you know which ones to watch? This article helps you identify which are the critical performance counters in a SharePoint Portal Server environment and explains how to monitor them. By monitoring performance regularly, organizations can recognize performance trends as they develop and prevent problems before they get out of hand.
    [Read This Article]  [Top]
    Aug 12, 2004 - Middle-Tier Hosting: Enterprise Services, IIS, DCOM, Web Services, and Remoting
    There is broad-reaching debate about remoting, Web services, Enterprise Services, and DCOM. In short, it is a debate about the best technology to use when implementing client/server communication in .NET. Rocky Lhotka shares his thoughts on the issue while offering clear explanations of basic application architecture terminology.
    [Read This Article]  [Top]
    May 18, 2004 - ASP.NET 2.0 Caching Features
    This article examines some of the new and exciting caching features in ASP.NET 2.0 and shows how to implement them in Web applications.
    [Read This Article]  [Top]
    Feb 12, 2004 - Case Study: Match.com
    When it came time to find a technology for its massive upgrade, Match.com chose .NET. Has the online dating service's partnership with Microsoft been as successful as the relationships it has established for many of its millions of members? Read on ...
    [Read This Article]  [Top]
    Jan 15, 2004 - Database Performance Philosophy
    Longtime 15Seconds discussion list member Tore Bostrup offers valuable advice on designing databases and applications for efficient querying.
    [Read This Article]  [Top]
    Dec 29, 2003 - Caching Oracle Data for ASP.NET Applications
    Narayan Veeramani shows how ASP.NET developers can improve application performance by caching data stored in an Oracle database and keeping the cached data in sync with the data in the Oracle database.
    [Read This Article]  [Top]
    Dec 2, 2003 - Leveraging MSMQ in ASP.NET Applications
    Ever developed a Web application that requires extensive processing? Ever had long running Web pages that often time out in the browser? Greg Huber reveals a simple technique that uses Microsoft Message Queuing (MSMQ) and the System.Messaging framework to handle long running Web processes.
    [Read This Article]  [Top]
    Mar 14, 2002 - Web Site Compression
    As IT professionals try to reduce the cost of operating their Web sites, they should consider reducing the amount of bandwidth usage. Learn how to successfully compress your HTML output and save money on your monthly bandwidth.
    [Read This Article]  [Top]
    Feb 6, 2002 - The Just Two Theory on Web Servers
    Maintaining a large Web farm is both costly and unnecessary. Learn how to reduce your Web farm to just two servers in this controversial article by Wayne Berry.
    [Read This Article]  [Top]
    Aug 14, 2001 - NT Authentication's Impact on Connection Pooling
    Steve Witkop examines OLE DB and ODBC connection pooling when used with Microsoft NT LAN Manager Web server authentication.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    IBM eBook: Planning a Service Oriented Architecture
    IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
    Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
    Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
    Intel Go Parallel Article: Getting Started with TBB on Windows
    Microsoft Article: 7.0, Microsoft's Lucky Version?
    Avaya Article: How to Feed Data into the Avaya Event Processor
    IBM Article: Developing a Software Policy for Your Organization
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    Intel Go Parallel Article: Intel Threading Tools and OpenMP
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    HP Video: StorageWorks EVA4400 and Oracle
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
    IBM Article: Enterprise Search--Do You Know What's Out There?
    HP Demo: StorageWorks EVA4400
    Microsoft Article: The Progress and Promise of Deep Zoom
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES