Click here to Skip to main content
15,881,882 members
Articles / Web Development / HTML

NTime - Performance unit testing tool

Rate me:
Please Sign up or sign in to vote.
4.73/5 (27 votes)
30 Mar 20066 min read 431.9K   8.2K   163  
An article on a performance testing tool to test an application against its performance
#region Copyright (c) 2004, Adam Slosarski
/************************************************************************************
'
' Copyright  2004 Adam Slosarski
'
' This software is provided 'as-is', without any express or implied warranty. In no 
' event will the authors be held liable for any damages arising from the use of this 
' software.
' 
' Permission is granted to anyone to use this software for any purpose, including 
' commercial applications, and to alter it and redistribute it freely, subject to the 
' following restrictions:
'
' 1. The origin of this software must not be misrepresented; you must not claim that 
' you wrote the original software. If you use this software in a product, an 
' acknowledgment (see the following) in the product documentation is required.
'
' Portions Copyright  2004 Adam Slosarski
'
' 2. Altered source versions must be plainly marked as such, and must not be 
' misrepresented as being the original software.
'
' 3. This notice may not be removed or altered from any source distribution.
'
'***********************************************************************************/
#endregion
using System;
using System.Windows.Forms;
using NTime.Framework;
using System.Collections;


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.

			// Configuration settings work as well.
//			string test = System.Configuration.ConfigurationSettings.AppSettings["testConfig"];
//			System.Windows.Forms.MessageBox.Show(test);

			// Even dynamically loaded assemblies do work.
//			System.Reflection.Assembly a = System.Reflection.Assembly.LoadWithPartialName("PerformanceTests");
//			MessageBox.Show(a.ToString());
//			foreach(System.Type t in a.GetTypes())
//			{
//				MessageBox.Show(t.FullName);
//			}
		}

		[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, because test specification or algorithm details are unknown for now.")]
		public void SuperSortAlgorithm()
		{
			// code here will not be profiled until TimerIgnore flag was removed.
		}

		[TimerCounterTest("Process", "% Processor Time", Threads = 1, InstanceName = "*", MinimumValue = 0, MaximumValue = 50)]
//		[TimerCounterTest("Process", "Handle Count", Threads = 1, InstanceName = "NTime", 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 < 3; i++)
			{
				System.Threading.Thread.Sleep(1000);
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


Written By
Web Developer
Poland Poland
Born in Poland, living there as employeed developer, in free time writing much .net stuff and designing applications.

Comments and Discussions