Click here to Skip to main content
15,886,519 members
Articles / Programming Languages / C#

NPerf, A Performance Benchmark Framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.92/5 (44 votes)
25 Jan 20044 min read 231.6K   705   139  
NPerf is a framework for benchmarking classes and methods, that tastes like NUnit.
using System;

namespace NPerf.Framework
{
	/// <summary>
	/// A performance tester class attribute.
	/// </summary>
	/// <include file='NPerf.Framework.Doc.xml' path='doc/remarkss/remarks[@name="PerfTesterAttribute"]'/>
	/// <include file='NPerf.Framework.Doc.xml' path='doc/examples/example[@name="PerfTesterAttribute"]'/>
	[AttributeUsage(
		   AttributeTargets.Class 
		 | AttributeTargets.Interface
		 | AttributeTargets.Struct, 
		 AllowMultiple=false,
		 Inherited=true
		 )]
	public class PerfTesterAttribute : Attribute
	{
		private Type testedType;
		private int testCount;
		
		private string description = null;
		private string featureDescription = null;

		/// <summary>
		/// Constructs the attribute
		/// </summary>
		/// <param name="testedType">target type</param>
		/// <param name="testCount">number of test runs</param>
		/// <exception cref="ArgumentNullException"><paramref name="testedType"/> is a null reference</exception>
		/// <exception cref="ArgumentException"><paramref name="testCount"/> is smaller than 1</exception>
		public PerfTesterAttribute(Type testedType, int testCount)
		{
			if (testedType==null)
				throw new ArgumentNullException("testedType");
			if (testCount<1)
				throw new ArgumentException("test count is smaller that 1");
			this.testedType = testedType;
			this.testCount = testCount;			
		}
		
		/// <summary>
		/// Gets the target type of the tester
		/// </summary>
		/// <value>
		/// Target type of the tester
		/// </value>
		public Type TestedType
		{
			get
			{
				return this.testedType;
			}
		}
		
		/// <summary>
		/// Gets the number of test runs
		/// </summary>
		/// <value>
		/// The number of test runs 
		/// </value>
		public int TestCount
		{
			get
			{
				return this.testCount;
			}
		}
		
		/// <summary>Gets the Test description string</summary>
		/// <value>Test description</value>
		public string Description
		{
			get
			{
				return this.description;
			}
			set
			{
				this.description = value;
			}
		}				
		/// <summary>Gets the tested feature description string</summary>
		/// <value>Tested feature description</value>
		public string FeatureDescription
		{
			get
			{
				return this.featureDescription;
			}
			set
			{
				this.featureDescription = value;
			}
		}				
	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions