Click here to Skip to main content
15,886,422 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.4K   705   139  
NPerf is a framework for benchmarking classes and methods, that tastes like NUnit.
using System;
using System.Xml;
using System.Xml.Serialization;


namespace NPerf.Core
{
	[Serializable]
	[XmlRoot("failed-result")]	
	public class PerfFailedResult
	{
		private string testedType;
		private string exceptionType;
		private string message;
		private string source;
		private string fullMessage;
		
		public PerfFailedResult()
		{
			this.testedType=null;
			this.exceptionType = null;
			this.message = null;
			this.source = null;
			this.fullMessage = null;
		}
		
		/// <summary>
		/// Default constructor - initializes all fields to default values
		/// </summary>
		public PerfFailedResult(Type testedType, Exception ex)
		{
			if (testedType==null)
				throw new ArgumentNullException("testedType");
			if (ex==null)
				throw new ArgumentNullException("ex");
			
			Exception iex = ex;
			
			if (ex.InnerException!=null)
				iex = ex.InnerException;
			this.testedType = testedType.Name;
			this.exceptionType = iex.GetType().Name;
			this.message = iex.Message;
			this.source = iex.Source;
			this.fullMessage = iex.ToString();
		}
		
		[XmlAttribute("tested-type")]
		public string TestedType
		{
			get
			{
				return this.testedType;
			}
			set
			{
				this.testedType = value;
			}
		}

		[XmlAttribute("exception-type")]		
		public string ExceptionType
		{
			get
			{
				return this.exceptionType;
			}
			set
			{
				this.exceptionType = value;
			}
		}
		
		[XmlElement("message")]		
		public string Message
		{
			get
			{
				return this.message;
			}
			set
			{
				this.message = value;
			}
		}
		
		[XmlElement("source")]		
		public string Source
		{
			get
			{
				return this.source;
			}
			set
			{
				this.source = value;
			}
		}
		
		[XmlElement("full-message")]		
		public string FullMessage
		{
			get
			{
				return this.fullMessage;
			}
			set
			{
				this.FullMessage = 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