Wednesday, March 13, 2013

String Comparision Performance Test

Comparasion done Replacing String.Compare with the below listed priorities.

we can priorities as follows:
  1. a == b - the most efficient and visual style
  2. String.Equals(a,b) - equally efficient but pain to read from the code
  3. a.Equals(b) - not fast but more sane than the Object one
  4. Object.Equals(a,b) - very obscure way to compare strings
  5. String.Compare(a,b)==0 - bad way to check equality
I have done a performance test below are the results.
 
Time Taken for comparing 100000000 Strings:

Time taken by == comparison 484 milliseconds
Time taken by CompareOrdinal method 537 milliseconds
Time taken by String.Compare method 18076 milliseconds
Time taken by String.Equals method 490 milliseconds

No comments:

Post a Comment