.NET性能单元测试 NTime
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); } } } }界面如下图所示:
本文由用户 openkk 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!