String.Empty vs ""

So I've always heard you should use String.Empty vs "" the dreaded blank string in C#. So I decided to write a little test program to find out. It simply takes a string variable and assigns it to "" or String.Empty. I do this 1 million times each and time how many milliseconds it takes to do that assignment. My system is a p4 1.5 GHz RAM running .net 2.0. Source code can be sent upon request. The results are surprising and can be seen below. Other then the first run the String.Empty beat the "" by a few milliseconds. Hardly the creaming I've read about. But perhaps if you were doing some severe number crunching you would notice a difference. However this test is hardly definitive and should probably be run several more times and had the numbers aggregated. I've run the app a lot more since yesterday but only added one more screenshot. I may just post the screen UI and then keep track of the results in a spreadsheet or modify the app to aggregate the results on it's own. Sometimes the "" wins but for the large part String.Empty appears to be slightly faster.

Run 1:

Run 2:

Run 3:

Run 4 (1 day later with a lot less apps running) :


Anonymous said…
interesting... it would be nice to make an additional test, checking a million strings against "" and string.Empty

Popular Posts