Thoughts from the office by Ed Ball
Wednesday, October 08, 2003

Instinctively,

  if (strGnusto != "")

is going to be less efficient than

  if (strGnusto.Length != 0)

when checking for an empty string, though I think the former is probably easier to read.

I decided that I'd do some rudimentary timing comparisons using JScript and C#. (Thanks to Jeff Key for Snippet Compiler!) The comparison using Length does seem to be more efficient than the comparison to "" -- about 1/5th the time in the (again, rudimentary) timing that I did.

No surprise, really, but I was hoping that the performance difference would be a bit less dramatic. As it is, I should probably start using the later syntax. The performance isn't going to matter in most cases, but consistency is best.

10/8/2003 10:42:05 AM (Pacific Daylight Time, UTC-07:00) | Comments [0] | Code#
Search
Archive
Links
Categories
Administration
Blogroll