?
=?ISO-8859-1?Q?G=F6ran_Andersson?=
It would be interresting to se how you did the test. When I test it I
get the result that IndexOf is slightly faster, but they never differ
more than a few percent.
Here is what I tested:
HighResolutionClock clock;
int pos;
double time1, time2;
string text, find;
text = "askdjf iuqwh peha sduuhböaos9 döqown eiluhas9ödhföoasid öfoiajsd
fä0sd föoiqwe fuh asilduhfasudh föoiqiweöf oihas dlifyg asliudhf
öoasihdf h";
find = "duhf";
clock = new HighResolutionClock();
clock.Reset();
for (int i = 0; i < 1000000; i++) pos = Strings.InStr(2, text, find,
CompareMethod.Text);
time1 = clock.Seconds;
clock.Reset();
for (int i = 0; i < 1000000; i++) pos = text.IndexOf(find, 1,
StringComparison.CurrentCultureIgnoreCase);
time2 = clock.Seconds;
Typical result:
time1: 3.589
time2: 3.519
(I can post the HighResolutionClock class if you want. It uses the
QueryPerformanceCounter method in kernel32.dll.)
get the result that IndexOf is slightly faster, but they never differ
more than a few percent.
Here is what I tested:
HighResolutionClock clock;
int pos;
double time1, time2;
string text, find;
text = "askdjf iuqwh peha sduuhböaos9 döqown eiluhas9ödhföoasid öfoiajsd
fä0sd föoiqwe fuh asilduhfasudh föoiqiweöf oihas dlifyg asliudhf
öoasihdf h";
find = "duhf";
clock = new HighResolutionClock();
clock.Reset();
for (int i = 0; i < 1000000; i++) pos = Strings.InStr(2, text, find,
CompareMethod.Text);
time1 = clock.Seconds;
clock.Reset();
for (int i = 0; i < 1000000; i++) pos = text.IndexOf(find, 1,
StringComparison.CurrentCultureIgnoreCase);
time2 = clock.Seconds;
Typical result:
time1: 3.589
time2: 3.519
(I can post the HighResolutionClock class if you want. It uses the
QueryPerformanceCounter method in kernel32.dll.)