/ Published in: C#
Just an example of timing code
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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);