CryptoPad Classic

String Comparisons
by Steven Noonan
June 15, 2005

Note: OPS = Operations Per Second

I actually wrote a function which improves the speed of StrComp if the strings are not of the same length (if the lengths aren't the same, it cannot be the same string). My function is called StringComp. You will see a huge difference in speed when we get to non-identical strings.

When doing string comparisons, and you want case insensitivity, you should always use StrComp, instead of an "if LCase$(StringOne) = LCase$(StringTwo)".

Below is a comparison of the speeds.

Identical Strings (Case insensitive)
LCase$(StringOne) = LCase$(StringTwo) StrComp(StringOne, StringTwo, vbTextCompare) = 0 StringComp(StringOne, StringTwo)
526,534 OPS 1,500,911 OPS 1,394,779 OPS

However, whenever you are doing a case-sensitive string comparison, you should use the StringOne = StringTwo, as it is significantly faster (shown below).

Identical Strings (Case sensitive)
StringOne = StringTwo StrComp(StringOne, StringTwovbTextCompare) = 0 StringComp(StringOne, StringTwo)
3,305,785 OPS 1,501,243 OPS 1,400,304 OPS

And if the strings are not identical (differential lengths), you do not see a dramatic difference between the methods, except for my StringComp method.

Non-Identical Strings (Case insensitive)
LCase$(StringOne) = LCase$(StringTwo) StrComp(StringOne, StringTwo, vbTextCompare) = 0 StringComp(StringOne, StringTwo)
510,484 OPS 1,369,553 OPS 15,010,511 OPS

Non-Identical Strings (Case sensitive)
StringOne = StringTwo StrComp(StringOne, StringTwo, vbTextCompare) = 0 StringComp(StringOne, StringTwo)
3,396,174 OPS 1,390,758 OPS 15,857,913 OPS


As is obvious, comparing the length before comparing the string will help the speed greatly.

Home
SourceForge Project Page
VB Performance
- String Comparisons
- Integers vs Longs
Uplink Laboratories

Note: While there are no plans for ceasing CryptoPad development, the development phase has been inactive for over six months. There is a possibility for a C version of CryptoPad Classic to be developed. Would anyone support this idea? If people would like development to continue, please let the lead developer know.

Support This Project Please donate for the sake of continued CryptoPad development!
This web page is Copyright © 2006 Uplink Laboratories. CryptoPad Classic is released under the GNU General Public License (GPL).
Athlon and Athlon XP are registered trademarks of AMD. Microsoft, Windows, Windows NT, Windows XP, Wordpad, and/or other Microsoft products referenced herein are either trademarks or registered trademarks of Microsoft. Intel and Pentium are registered trademarks of Intel. Additional company and product names may be trademarks or registered trademarks of the individual companies and are respectfully acknowledged.
SourceForge.net Logo