Revision: 11194
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 27, 2009 18:02 by niik
Initial Code
var a = "foo bar foo"; var b = "foo"; int numTimes = 1000000; var swOrdinal = Stopwatch.StartNew(); for (int i = 0; i < numTimes; i++) a.StartsWith(b, StringComparison.Ordinal); swOrdinal.Stop(); Console.WriteLine("Ran {0:N0} ordinal iterations in {1}ms", numTimes, swOrdinal.Elapsed.TotalMilliseconds); var swCulture = Stopwatch.StartNew(); for (int i = 0; i < numTimes; i++) a.StartsWith(b); swCulture.Stop(); Console.WriteLine("Ran {0:N0} culture-sensitive iterations in {1}ms", numTimes, swCulture.Elapsed.TotalMilliseconds);
Initial URL
Initial Description
Just an example of timing code
Initial Title
Timing different variants of string.StartsWith
Initial Tags
Initial Language
C#