Data Access Worldwide Knowledge Base

Article ID 2330
Article Title INFO: Speed of large string concatenation
Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2330
KBase Category MISCELLANEOUS
Date Created 06/19/2007
Last Edit Date 07/12/2007


Article Text
PROBLEM:
I noticed that when I work with strings, particular LARGE strings, the time that is involved to build them can be quite long. Some of my routines take up to 1 minute 53 seconds to build up the result. Since this is done in a web environment, there are two problems:
1) The response is very late causing people to close the browser, navigate away etc
2) Sometimes we run in a time-out (set to 2 minutes) and people get an error

ANSWER:
When you work with large strings you are working with memory allocations/reallocations and copying. Speed all depends on paging/caching, how efficient the memory manager is at allocating small/large chunks of memory as well as disposing the memory (i.e. freeing up memory).

If your program does something like:

Move '' To sLongString
For iLoop From 1 to 1000000
    Move (sLongString + 'x') to sLongString
Loop

it is much slower than when you do:

Move '' To sLongString
For iLoop From 1 to 1000
    Move '' to sTemp
    For iLoop2 From 1 to 1000
        Move (sTemp + 'x') to sTemp
    Loop
    Move (sLongString + sTemp) To sLongString
Loop

In the above example we found a difference in the order of 50 times -- where the first routine took 53 seconds, the second one took just over 1 second to complete.

NOTE:
This is NOT specific to (Visual) DataFlex. It happens in other programming environments as well, such as Javascript, XSLT scripts, 'C' etc.



Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.