Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

NPerf, A Performance Benchmark Framework for .NET

, 25 Jan 2004
NPerf is a framework for benchmarking classes and methods, that tastes like NUnit.
nperf_bin.zip
Release
NPerf.Cons.exe
NPerf.Core.dll
NPerf.Framework.chm
NPerf.Framework.dll
NPerf.Report.dll
scpl.dll
System.Perf.dll
nperf_demo.zip
Releases
Unpackaged
nperf-1.1-Release
nperf
bin
Release
nperf-doc-1.1.chm
NPerf.Cons.exe
NPerf.Core.dll
NPerf.Framework.dll
NPerf.Report.dll
scpl.dll
System.Perf.dll
nperf_src.zip
src
build
NAnt
i18n.xsl
ICSharpCode.SharpCvsLib.dll
ICSharpCode.SharpZipLib.dll
log4net.dll
NAnt.Contrib.Tasks.dll
NAnt.Core.dll
NAnt.DotNetTasks.dll
NAnt.exe
NAnt.NUnit.dll
NAnt.NUnit1Tasks.dll
NAnt.NUnit2ReportTasks.dll
NAnt.NUnit2Tasks.dll
NAnt.SourceControlTasks.dll
NAnt.VisualCppTasks.dll
NAnt.VSNetTasks.dll
NAnt.Win32Tasks.dll
NAnt.ZipTasks.dll
NDoc.Core.dll
NDoc.Documenter.Msdn.dll
NDoc.Documenter.NAnt.dll
NUnit-Frame.xsl
NUnit-NoFrame.xsl
nunit.framework.dll
NUnitCore.dll
toolkit.xsl
NPerf.Cons
Collections
App.ico
NPerf.Cons.cmbx
NPerf.Cons.prjx
NPerf.Core
Collections
Monitoring
Tracers
NPerf.Core.cmbx
NPerf.Core.prjx
NPerf.Framework
NPerf.Framework.cmbx
NPerf.Framework.prjx
NPerf.Report
scpl
scpl.dll
System.Perf
NPerf.Framework.chm
nperf.ndoc
nperf.png
namespace System.Perf 
{
	using System;
	using NPerf.Framework;

	// a dummy class with empty call method
	public interface IMethodCall
	{
		void Call();
		void Call(object sender, EventArgs args);
	}
	
	public class MethodCall : IMethodCall
	{		
		public void Call()
		{}
		public void Call(object sender, EventArgs args)
		{}
	}

    // the method caller interface
	public interface IMethodCaller
	{
		void SetMethod(IMethodCall m, int n);
		void CallMethod();		
	}
	
	// first test class, that uses interface call
	public class InterfaceMethodCall : IMethodCaller
	{
		int n = 0;
		IMethodCall mc = null;
		
		public void SetMethod(IMethodCall mc, int n)
		{
			this.n = n;
			this.mc = mc;
		}
		public void CallMethod()
		{
			for(int i = 0;i<n;++i)
				mc.Call();
		}
	}
	
	public delegate void MyDelegate();	
	
	public class DelegateMethodCaller : IMethodCaller
	{
		int n = 0;
		event MyDelegate d = null;
		
		public void SetMethod(IMethodCall mc, int n)
		{
			this.n = n;
			this.d += new MyDelegate(mc.Call);
		}
		public void CallMethod()
		{	
			for(int i = 0;i<n;++i)
				d();			
		}
	}
	
	public class EventHandlerMethodCaller : IMethodCaller
	{
		int n = 0;
		event EventHandler d = null;
		
		public void SetMethod(IMethodCall mc, int n)
		{
			this.n = n;
			this.d += new EventHandler(mc.Call);
		}
		public void CallMethod()
		{	
			for(int i = 0;i<n;++i)
				d(this, new EventArgs());			
		}
	}

	
	[PerfTester(
	            typeof(IMethodCaller),
	            50,
	            Description="Comparing interface and delegate calls",
	            FeatureDescription="Method call number"
	            )]
	public class DelegateInterfaceTester
	{
		internal int CallCount(int index)
		{
			if (index<0)
				return 10;
			else
				return (int)Math.Floor(Math.Pow(index,2)*1000);						
		}
		[PerfRunDescriptor]
		public double RunDescriptor(int index)
		{
			return (double)CallCount(index);			
		}
		
		[PerfSetUp]
		public void SetUp(int index, IMethodCaller mc)
		{
			mc.SetMethod(new MethodCall(), CallCount(index));
		}
		
		[PerfTest]
		public void Call(IMethodCaller mc)
		{
			mc.CallMethod();
		}
	}
}

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

Share

About the Author

Jonathan de Halleux
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).

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150414.1 | Last Updated 26 Jan 2004
Article Copyright 2004 by Jonathan de Halleux
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid