(原創) 如何對程式片段進行效能測試(benchmark)? (.NET) (C#)
/*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : Benchmark.cs
Compiler : Visual Studio 2005 / C# 2.0
Description : Demo simple benchmark
Release : 09/09/2007 1.0
*/
using System;
class Client {
static void sub() {
for (int i = 0; i != 100000; ++i)
for (int j = 0; j != 100000; ++j);
}
static void Main() {
DateTime t = DateTime.Now;
sub();
TimeSpan span = DateTime.Now.Subtract(t);
Console.WriteLine("Process time:{0}.{1} sec",span.Seconds.ToString(),span.Milliseconds.ToString()) ;
}
}
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : Benchmark.cs
Compiler : Visual Studio 2005 / C# 2.0
Description : Demo simple benchmark
Release : 09/09/2007 1.0
*/
using System;
class Client {
static void sub() {
for (int i = 0; i != 100000; ++i)
for (int j = 0; j != 100000; ++j);
}
static void Main() {
DateTime t = DateTime.Now;
sub();
TimeSpan span = DateTime.Now.Subtract(t);
Console.WriteLine("Process time:{0}.{1} sec",span.Seconds.ToString(),span.Milliseconds.ToString()) ;
}
}
See Also
(原創) 如何對程式片段進行效能測試(benchmark) (C/C++)
Reference
Stenven A.Smith, Rob Howard, The ASP Alliance,.ASP.NET developer's cookbook, 2004