Representative Line: A Memory of Strings

This post was originally published on this site

The Daily WTF

As we saw yesterday, padding can be hard.

Jasmine received a set of tickets all complaining that the file download portion of an ASP .Net application took too long. Users frequently had to wait for up to 15 minutes before their browser finished downloading the output of the web application.

This particular module generated the file by doing a set of Response.Writes to build the file as part of the HTTP response. This particular line ran 200,000 times in the process of creating the file:

myResponse.Write(“P;P#,##0.” + new string(‘0’, 2) + “_);;[Red](#,##0.” + new string(‘0’, 2) + “)n”);

I’m not entirely clear what they’re writing out here- it looks like some kind of format template. But the contents don’t really matter. The string concatenation operations look like they’re handling decimal places- 0.00. Given that the new string is hard coded to two zeros, there’s no need for string concatenation,

To read the full article click on the 'post' link at the top.