String Surprise

String Surprise

I was developing a CGI application that read a database and pieced together the fields into a string forrepresentation as an HTML form. The surprise came when I found how slow it was-20 seconds wasunacceptable for the task. I first suspected the database access and thought there was no way to improve it;however, upon investigating further, it turned out to be the loop that concatenated the fields into the string. Asimple change took the run time of the routine down to about one second. In this simplified example, insteadof writing this code:

 For i = 1 To 10000        strHTML = strHTML & strField & vbTabNext i

Break it down into something like this:

 For i = 1 To 100        strTemp = ""        For j = 1 to 100                strTemp =  strTemp & strField _                        & vbTab        Next j        strHTML =  strHTML & strTemp Next i

Admittedly, the number of concatenations is high, but the difference is astounding. In the 16-bit world, thesecond example is about 20 times faster than the first on my machine. However, in VB 32-bit, my Pentium133 with 32 MB RAM takes 48 seconds for the first case and less than one second for the second case. Ihesitate to suggest a precise speed improvement because of the complexity of Windows 95 and differenthardware, but if you must concatenate large numbers of strings, this could become a make-it-or-break-itproblem.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular