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
using System;
using System.Reflection;
using System.Xml;
using System.Xml.Serialization;
using System.Drawing;
using System.Drawing.Imaging;
using System.Collections;
using System.IO;

namespace NPerf.Cons
{
	using NPerf.Core;
	using NPerf.Core.Collections;
	using NPerf.Report;
	using NPerf.Core.Tracer;

	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			try
			{
				ClArguments cl = new ClArguments();
				cl.AddParameter(new ClParameter("testera","ta","Tester Assembly",false,false));
				cl.AddParameter(new ClParameter("testeda","tdfa","Tested Assembly",false,false));
				cl.AddParameter(new ClParameter("testedapartial","tdfap","Tested Assembly Parital Name",false,false));
				cl.AddParameter(new ClParameter("ignoredtype","it","Ingored types",false,false));
				cl.AddParameter(new ClParameter("verbose","v","Verbose",true,true));
				cl.AddParameter(new ClParameter("outputtype","ot","Output type",true,false));
				cl.AddParameter(new ClParameter("xml","x","Output as XML",true,true));

				cl.Parse(args);
				cl.ProcessHelp();


				// loading testers
				if (!cl.ContainsDuplicate("ta"))
					throw new Exception("You did not specify a tester assembly");

				// load testers
				PerfTesterCollection testers = new PerfTesterCollection();
				foreach(String name in cl.Duplicates("ta"))
				{
					Console.WriteLine("Load tester assembly: {0}",name);
					PerfTester.FromAssembly(
						  testers,
						  Assembly.LoadFrom(name)
						  );
				}
				if (testers.Count == 0)
					throw new Exception("Could not find any tester class");

				// load tested
				foreach(PerfTester tester in testers)
				{
					if (tester.IsIgnored)
						continue;		
			
					if (cl.ContainsDuplicate("tdfa"))
					{
						foreach(String name in cl.Duplicates("tdfa"))
						{
							Console.WriteLine("Load tested assembly: {0}",name);
							tester.LoadTestedTypes(Assembly.LoadFrom(name));
						}
					}

					if (cl.ContainsDuplicate("tdfap"))
					{
						foreach(String name in cl.Duplicates("tdfap"))
						{
							Console.WriteLine("Load tested assembly: {0}",name);
							tester.LoadTestedTypes(Assembly.LoadWithPartialName(name));
						}
					}

					Console.WriteLine("Tested types:");
					foreach(Type t in tester.TestedTypes)
					{
						Console.WriteLine("\t{0}",t.Name);
					}

					// removing types
					if (cl.ContainsDuplicate("it"))
					{
						foreach(String name in cl.Duplicates("it"))
						{
							Console.Write("Ignoring type: <{0}>",name);
							Type t = Type.GetType(name);
							if (t==null)
								Console.WriteLine(" - could not load type.");
							else
							{
								if (tester.TestedTypes.Contains(t))
								{
									Console.WriteLine(" removed");
									tester.TestedTypes.Remove(t);
								}
								else
									Console.WriteLine("-- could not remove {0}",t.Name);
							}
						}
					}
				}

				// run test
				ChartReport chart = new ChartReport(800,400);
				chart.Colors.Map = ColorMap.Jet;
				ImageFormat im = ImageFormat.Png;

				if (cl.ContainsUnique("ot"))
				{
					switch(cl.Unique("ot").ToLower())
					{
					case "png":
							im = ImageFormat.Png;
							break;
					case "gif":
						im = ImageFormat.Gif;
						break;
					case "jpeg":
						im = ImageFormat.Jpeg;
						break;
					case "bmp":
						im = ImageFormat.Bmp;
						break;
					case "emf":
						im = ImageFormat.Emf;
						break;
					}
				}

				foreach(PerfTester tester in testers)
				{
					if (tester.IsIgnored)
						continue;

					TextWriterTracer tracer = new TextWriterTracer();
					tracer.Attach(tester);
										
					PerfTestSuite suite = tester.RunTests();

					if (cl.ContainsUnique("xml"))
					{
						using (FileStream file = File.OpenWrite(tester.TestedType.Name + "." + suite.Name + ".xml"))
						{
							StreamWriter writer = new StreamWriter(file);
							suite.ToXml(writer);
							writer.Close();
						}
					}
										
					IDictionary bmps = chart.Render(suite);
					foreach(DictionaryEntry de in bmps)
					{
						PerfTest test = (PerfTest)de.Key;
						Bitmap bmp = (Bitmap)de.Value;
						bmp.Save(tester.TestedType.Name + "." + test.Name + "." + im.ToString().ToLower(),im);
					}
				}
			}
			catch(Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}
		}
	}
}

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 | Mobile
Web02 | 2.8.140814.1 | Last Updated 26 Jan 2004
Article Copyright 2004 by Jonathan de Halleux
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid