.NET性能单元测试 NTime
openkk
13年前
NTime 是一款用来测试 .NET 应用性能的单元测试工具,
using System; using NTime.Framework; namespace NTime.Tests { /// <SUMMARY> /// This is a tested class. /// </SUMMARY> [TimerFixture] public class TestClass { [TimerFixtureSetUp] public void GlobalSetUp() { // initialize one-time initialization data in // this testfixture. } [TimerFixtureTearDown] public void GlobalTearDown() { // release one-time initialized data in // this testfixture. } [TimerSetUp] public void LocalSetUp() { // initialize data for every test found // in this testfixture class } [TimerTearDown] public void LocalTearDown() { // release data for every finished test // found in this testfixture class } [TimerHitCountTest(300, Threads = 3, Unit = TimePeriod.Second)] public void WebRequest() { // invoke some code from real application // to test its functions against specified // performance. // in example we will keep our fictional // web server's response at 10 milliseconds if(System.Threading.Thread.CurrentThread.Name == "NTimeThread_0") System.Threading.Thread.Sleep(5); else if(System.Threading.Thread.CurrentThread.Name == NTimeThread_1") System.Threading.Thread.Sleep(8); else System.Threading.Thread.Sleep(10); } [TimerDurationTest(20, Unit = TimePeriod.Millisecond)] public void GameScreenFlicking() { // we want to calc game AI, 3d engine and // other stuff to keep it running at 50Hz // vertical screen sync. System.Threading.Thread.Sleep(5); } [TimerDurationTest(10, Unit = TimePeriod.Millisecond)] [TimerIgnore("This test is disabled.")] public void SuperSortAlgorithm() { // code here will not be profiled until TimerIgnore // flag was removed. } [TimerCounterTest("Process", "% Processor Time", Threads = 1, InstanceName = "NTimeGUI", MinimumValue = 0, MaximumValue = 50)] public void ProcessorUsage() { // we want to see whether our application is // optimized to work with minimal CPU usage. for(int i = 0; i < 150; i++) { System.Threading.Thread.Sleep(30); } } } }界面如下图所示: