.net - Does whitespace matter when using StringBuilder to generate HTML server side? -
I am thinking that using whitespace (for readability) using stringbilders to represent weed There is no negative impact on time performance.
Take this simple example:
str.AppendLine ("& lt; div>") str.AppendLine ("& lt; span & gt; Test & Lt; / span & gt; ") Unlike the Str.AppendLine (" & lt; / div & gt; ") :
str .AppendLine ("& lt; div & gt;") str Appendable (" test ") str.AppendLine ("& lt; / div & gt;") Why am I searching for details of explanation as much as possible?
The answer is: It depends if you have a lot of white space with non-whitespace equivalent If you are doing a number of operations then the impact on will will be affected. Here is a benchmark test:
dim t1 = task Run (new function) (function () slow start = now dim sb as new system. 5000000 sb.AppendLine for text.StringBuilder i = 1 ("my value") Next sb.ToString () Return now - Dim t2 = Task.Run (new function (of the timespace) (function ()) Dim Start = now dim sb as new System.Text.StringBuilder I = 1 for 5000000 sb.AppendLine ("My value" ) Next sb.ToString () now back - Start Termination function)) Debug. Print (string.format ("Whitespace with (ms):" & amp; T1.Result.Milliseconds) debug. Print (String.format ("Without White Location (MS):" & amp; T 2. Result. Mediaesconds) This is an extreme example where compared to non-whitespace in each line In this example, the output is: Viruspace (MS): 757
Without white space (MS), there is a lot of additional white space, and it creates five million lines. : 371
However, if you reduce the number of lines made of half and half Rati line reduces the amount of additional extra white space, then output is:
Viruspace (MS): 223
WhiteSpace (MS): 175 >
and then the number of lines and white space again again (half a quarter of the original):
Whitespace (MS): 87
without whitespace (ms): 66
The thing is that it is true, it will have an effect, but it depends on whether you How are you using, and in the end, this is only the difference between a few hundred milliseconds in extreme cases, ultimately it depends on you (and your colleagues) to determine that each situation What's important: Readability for the programmer or accountability for the user.
Comments
Post a Comment