Stopwatch time = new Stopwatch();
byte[] target = new byte[size];
for (int j = 0; j < size; j++)
target[j] = unchecked((byte)j); //Otherwise parts of the array are optimised out.
CCMD5Core.GetHash(target);
time.Start();
for (int i = 1; i <= iterations; i++)
{
target[0] = unchecked((byte)i);
CCMD5Core.GetHash(target);
}
time.Stop();
TimeSpan ts = time.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format(CultureInfo.CurrentCulture, "Total time for core iterations: \t{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine(elapsedTime, "RunTime");
wp8 入门到精通 测量代码执行时间,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/luquanmingren/p/3789774.html