Click here to Skip to main content
Click here to Skip to main content

NTime - Performance unit testing tool

By , 30 Mar 2006
 

Introduction

This article presents a unique tool to run repeatable performance tests in an application developed by programmers. The NTime tool is very similar to NUnit tool - another unit testing tool, so the users of NUnit will find an almost similar GUI and functionality.

Background

This is the first release of the tool that performs repeatable tasks to help managers, architects, developers and testers test an application against its performance. This version may not be very consistent and it may report errors under different situations. However, the tool was tested under many situations.

Tool usage

This section provides information for the application management team that wishes to use NTime tool to keep applications working at the desired performance level.

Managers

Program managers are welcome to specify application performance boundaries at the beginning of the application development process. They may also note which modules and functions of the application need to work and at which time frames. The performance specifications written by them may be helpful for developers when designing the application performance. Further, the NTime tool tests their performance specifications against real, developed applications. The tests performed by NTime tool may be reproduced at different time periods to see whether the application is giving the expected performance. But the main advantage of using this tool is that it enables managers to create configuration test files for developers and testers to give them a starting point on how to optimize the application.

Developers

Developers use NTime tool to test whether their application works in accordance with the performance specifications designed by managers or by themselves. They need to run the NTime tool when they aren't sure whether their rewritten code still works well. The NTime tool can also be made to remain open on the desktop even when the programmers develop, compile or debug their applications - every application that is built will be reloaded in NTime automatically and shown with the updated tests.

Testers

Testers are actively in the performance test stage. They run repeatable tests after every application's alpha release. Testers will review hundreds or thousands of tests and register them to the bug tracing applications.

Architecture

NTime architecture is similar to that of NUnit tool. This section shows the features found in NTime tool.

Simultaneous compile and test time

NTime tool may still be running even when the compilation process of the application that we want to test is going on. After the application has been built, NTime will reflect all the changes, you just need to run the tests and wait for the performance test results whether they are accepted or rejected.

Test timings

Actually, NTime's timings are based on high frequency timers that rely on different onboard chipsets' architecture. This difference generates more or less precision in the performed tests. The disadvantages, while profiling the tests, include system processes and CPU load. Even after closing the heavy loaded applications, there may be other bad things that can occur - like, NTime needs some CPU and threads to perform complex tests and therefore you can indicate about 10 microseconds overhead, so if you want to test high frequency running functions, then you need to write inside of the test code a "for" loop statement i.e. 100 loops, and then test the result for the specified time multiplied by 100.

SDK documentation

NTime tool is supported by two documentation files. The NTime Framework SDK will be your starting point to test your applications against performance tests by adding .NET attributes into your code.

NTime framework SDK

NTime Framework SDK is the often used SDK documentation. This help file shows you the available .NET attributes that you can use in your testing applications. Many attributes are similar to that of NUnit attributes, so if you've used NUnit tool before, then working with NTime will be quite easy.

NTime GUI SDK

After the installation of NTime, you will find the NTime source documentation. This will help you to add some functionality to NTime, but remember every change that you make to this tool is only for your private and non-commercial use. Read License.rtf file for further information about NTime licensing.

Further development

This NTime version is a GUI only application. In future, I plan to develop a console application to provide batch script usability. For further improvements, you may send comments to adamslosarski@tlen.pl with your suggestions to help me make the application work better. Bugs found in this release will be fixed in the next version, so the earlier found errors will be corrected as soon as possible. The source code of NTime will be soon available on the sourceforge.net website, so you can track the latest versions.

Using the code

Below, you can see a sample code which uses all the attributes available with NTime framework. See the NTime framework SDK documentation for more information:

using System;
using NTime.Framework;

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.
        }

        [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.")]
        public void SuperSortAlgorithm()
        {
            // code here will not be profiled until TimerIgnore
            // flag was removed.
        }

        [TimerCounterTest("Process", "% Processor Time", 
          Threads = 1, InstanceName = "NTimeGUI", 
          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 < 150; i++)
            {
                System.Threading.Thread.Sleep(30);
            }
        }
    }
}

Points of interest

This tool contains some .NET technologies used inside the code, including application domains and .NET remoting - these technologies were introduced to allow simultaneous compile and run test functionality, so that the assemblies may be loaded into separate application domains which run shadowed assemblies, and so the original ones may be overwritten by the compiler. Also, the assemblies can be unloaded from the application domain anytime.

The second thing is the file monitoring which tracks file changes and refreshes the project test tree to reflect changes in the assemblies when a new DLL is deployed.

History

  • 2006-03-28
    • Bug fixes:
      1. Tested methods were launched five times to average time, but the LocalSetup method was launched only once. Now it is launching both during every test method call.
    • Improvements:
      1. Added named threads to detect which thread is executing the test method. Look at the example method 'WebRequest'.
  • 2005-04-05
    • Bug fixes:
      1. Tested assemblies could not read the application configuration settings.
      2. NTimeSetup.exe installer failed when the source files were being selected for installation.
    • Improvements:
      1. New option dialog box allows you to specify the application configuration settings file.
      2. NTime.Framework.dll was promoted to GAC to allow for better shared reference to it.
  • 2004-12-08
    • Updated NTime application with bug fixes and an additional console mode.
  • 2004-05-14
    • Added source code and documentation download separately.
  • 2004-05-11
    • First release of NTime tool.

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

About the Author

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralNice tool, but...memberjconwell8-Dec-04 9:25 
Nice tool, but after using it, I still prefer using Nick Weinholt's tool Performance Measurement Framework[^]. It gives a better set of result statistics to base your performance decision on.
 
John C

GeneralRe: Nice tool, but...memberAdamSlosarski8-Dec-04 23:03 
>> It gives a better set of result statistics to base your performance decision on.
 
Probably you're right because you talk about profiler which must show result very clearly, but my application is a more unique tool and it's not any next profiler like NumegaDevpartner profiler, AQTime, NPerf or NProf - they are working the same way with more or less additional features.
 
My .NTime tool provides unit testing - i think you don't understand the difference between performance tools and performance unit testing tools. NTime lets you type a boundaries like how fast the method should be in whole product cycle from design to deplyoment and maintenance. Next good thing in .NTime tool is that you can very simple attribute your methods as you work almost the same way as in NUnit, MBUnit, CSUnit etc. Performance Measurement Framework does it using delegates, invocation lists etc it is not comfortable to use - better solution is attributed methods like in NUnit, NTime etc.
 
Example about difference NTime and Performance Measurement Frame..:
 
a)Performance Measurement Framework gives you results how fast is your implemented method and you can decide to improve perfomance
 
b)NTime gives you result (also how fast is your methods but...) but in general result are whether your method test pass or fail, i mean if your method works slower after one month because you forgot about that method but it is invoking certain algorithm method which you changed and resulting in performance degradation then NTime will tell you that the first method has failed test, so you will remember that you changed something in other methods that resulted in perfomance degradation of tested method - you just get info that method pass or fail - and this depends on performance (not work/don't work logic like in nunit)
 


 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: Nice tool, but...memberjconwell11-Dec-04 17:31 
Its pretty obvious that you did not read anything from the link i posted. this is not a profiler, but a performance unit testing tool. It provides a more accurate time measurement (via the win32 api that it uses) and much more usable result report.
 
Please dont preach to people like they are idiots, especially when you have obviously not done YOUR homework.
 
John Conwell

GeneralRe: Nice tool, but...memberAdamSlosarski12-Dec-04 23:31 
>> Its pretty obvious that you did not read anything from the link i posted
 
You're wrong - i found harness (application - is it this you talk about?). And....
 
1) I do not see any function that uses WinApi to more accurate measure time (my NTime uses high resolution timers) - could you show me this api you talk about in harness?
 
2) You even still not understand. I dont need any graphics reports!!! These reports are good for profilers when i want to see my fixes in code in last build comparing to actual. I just need to know that my function has passed test and it's all i want. Because i am running big project about 800.000 lines code and i do not need to look for graphics report in each class but i want to have report that will show me that about 30 classes are to slow in my project containing 10.000 classes. Got it????? i think you'll not understand it ever. NTime is really unit testing. Which let you event very easy attribute your classes, i saw source code of harness and there is many complex function to use before getting started. Also where is the GUI to load some assemblies and point some methods to test??? NTime lets you open assembly in GUI and select with methods wiil be unit tested. Again - look forward for differences about performance unit testings and after- run profilers (some profilers are realtime like AQTime or devpartner profiler)
 
Read some good technical article of Marc Clifton about Classification of Unit Tests. Marc Clifton has written message in my discussion board and you can there see in his article very good knowledge you need.
 
If you think i'm not right in my sentences please provide here examples and facts what you can do more with harness (Measurement framework) and can't you do with NTime
 
Adam Slosarski
 

 

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
Generalperformance load testingmemberjosepinchero30-Jul-04 9:09 
Hello,
 
How would I use NTime:
 
I dont need to timebox the test trial...i need to "put it under load" and record the resulting time.
 
I want to compare two different ways of doing things.
GeneralRe: performance load testingmemberAdamSlosarski2-Aug-04 22:04 
Hi,
 
You probably need tool to profile your application and test performance against two different fixes in your code. The tool you look for is QTime 3.0 (Automated QA company - commercial), NProf (free tool), Compuware Devpartner profiler (free) or other.
 
NTime is just as name says the tool to do a tests but not to profile and collect results each run to compare results. NTime tool need to specify time boundaries and let you keep your application not exceed this boundary, so you have to write code efficiency and perhaps you won't forget about slow functions because NTime will signal that your routine is going to be slow.
 
NTime is not a profiler, it is a performance black-box test.

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: performance load testingmemberAdamSlosarski7-Dec-04 22:38 
Hi,
 
New NTime version is available to download.
* Bug fixes
* Added console mode to integrate with other applications, tools and addins

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
Generalconfig filesmemberjosepinchero28-Jul-04 14:03 
Hello,
 
Does NTime load config files like NUnit?
 
If i create a NTime perf test assembly, and want to use a app.config file this assembly, will NTime load the assembly if i postbuild copy app.config to xxxx.dll.config where the assembly is loaded from?
 
THis is a nice NUnit feature. Not exactly sure how it works tho...
 

GeneralRe: config filesmemberAdamSlosarski28-Jul-04 22:00 
Hi,
 
It's hard to answer, the source code doesn't implement any additional functionality about *.config files - the code is loading assemblies by default. Assemblies are loaded into separate application domain within NTime process. You have to find out how assemblies have to be loaded in the source code and debug it if necessary to see as it loads .config files. I am still just learning .net and didn't use appconfig files yet in my apps.

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: config filesmemberAdamSlosarski7-Dec-04 22:33 
Hi,
 
New NTime version is available to download.
* Bug fixes
* Added console mode to integrate with other applications, tools and addins

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: config filesmemberAdamSlosarski5-Apr-05 1:10 
New NTime version 1.3.0.0 from 31 March 2005 is available - it works with appconfigs now. new version you can find at www.gotdotnet.com or wait here few days in order to upload by me onto codeproject

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralNPerf, A Performance Benchmark Framework for .NetmemberWcohen23-May-04 4:36 
What is the difference with NPerf (from Jonathan de Halleux)
(from this codeproject article: http://www.codeproject.com/gen/design/nperf.asp[^])
 
I haven't been able to test any out (currently my main focus is on the 'make it work, make it right' than the 'make it fast')
GeneralRe: NPerf, A Performance Benchmark Framework for .NetmemberAdamSlosarski23-May-04 22:08 
NPerf tool is rather interface-typed test model, you write method wich expects interface type and then you tell which assembly to test, in example you may provide "system" assembly which holds many interfaced collections and then you can quick get result of all interfaced objects which uses IDictionary or other Interface, so you can see time difference between objects inherited from the same interface (Interface typed test driven model). The reports are rather static or more dynamic when you provide your custom interfaces.
 
NTime is a test tool that do not depend on interfaces, of course you can also test interfaces but NPerf is a better solution when looking on difference for objects inherited from one interface (You'll write less code) but NPerf will not test your application blocks against performance the way the NTime does.
 
You can run both tools and use them together, they are mutually exclusive tools. NTime is other tool than NPerf.
 
If you are beginner programmer your focus on 'make it work' is right for you, later when you'll get experience you can think on 'make it fast'.
 


 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: NPerf, A Performance Benchmark Framework for .NetmemberWcohen24-May-04 5:46 
I am currently trying out the eXtreme Programming principles from Ron Jeffries Book. In which he mainly focusses on 'make it work'. By refacturing his code (dailly) he applies the make it right. I rather like his approach (I am still finding my own ballance). Almost all (agile) programming comes down to make it work, make it right, make it fast. (I AM still a beginner when it comes down to winform programming and all the .Net related stuff... Which does not mean that I don't focus on the other two aspects. I just didn't use tools until now DateTime differences in my code = UGLY Blush | :O ).
 
Thanks for explaining the differences between nTime and nPerf...
Great Article! I'll be using nTime soon.
GeneralRe: NPerf, A Performance Benchmark Framework for .NetmemberAdamSlosarski24-May-04 21:18 
That's fine you study such books. Those are very helpful in programming stage. When you be ready, think about NTime, NUnit and other helper tools, these apps will speed up your application and keep it free of bugs.
 
Thanks for enjoying NTime.

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: NPerf, A Performance Benchmark Framework for .NetmemberAdamSlosarski7-Dec-04 22:34 
Hi,
 
New NTime version is available to download.
* Bug fixes
* Added console mode to integrate with other applications, tools and addins

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralcsUnitmemberRamon Smits18-May-04 9:28 
So what about http://www.csunit.org/ ? What features would make me want to use your tool?
or Advance Unit Test ( http://aut.tigris.org/ )?
GeneralRe: csUnitmemberAdamSlosarski18-May-04 22:46 
Your tool is a simple clone of NUnit or NUnit is a simple clone of your CSUnit, both have the same features and attributes. The AUT project is still without features that NTime implements.
 
NTime is a PERFORMANCE unit testing tool not a pass/failure logic unit testing. Read this document to see what are performance tests. This is one of first unique tool to do performance unit tests, not pass/failure tests instead.
 
NTime is appropriate application to test the code as it works with desired timings, these tests make sure your application still works without performance degradation.

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: csUnitmemberRamon Smits19-May-04 12:42 
I am familiar with performance tests. And aut really does monitor the time taken to execute a textfixture. These are reported by AUT. You can even see that on the screenshots of the project page http://aut.tigris.org/
 
Ok csUnit does not have that functionality but aut is ofcourse the best among unittest tools.
 
Where your tool could win some point is that you can monitor performance counters easily within a fixture and define tressholds on those to see it the fixture passes performance requirements. None of the current tools has that ability.
 
A unit test tests a unit of code for a specific outcome. That outcome could be that you expect a specific result in functionality but that could easily be a tresshold value too in the form of the difference of a performance counter begin and end values.
GeneralRe: csUnitprotectorMarc Clifton5-Apr-05 13:18 
AdamSlosarski wrote:
The AUT project is still without features that NTime implements.
 
That is not correct.
 
Marc
 
MyXaml
Advanced Unit Testing
YAPO
 

GeneralRe: csUnitmemberAdamSlosarski5-Apr-05 23:55 
Of course you're right, i was probably thinking about CSUnit but saying about AUT. Does CSUnit run performance tests too?
 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: csUnitmemberAdamSlosarski7-Dec-04 22:38 
Hi,
 
New NTime version is available to download.
* Bug fixes
* Added console mode to integrate with other applications, tools and addins

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralNormalizeTime not rightmemberbierdopje18-May-04 3:21 
RemoteLoader.NormalizeTime, RemoteLoader.NormalizeHitcount and RemoteLoader.TimeToNanoseconds assume that the factor between seconds and minutes 1000 is, while it is 60.
The same goes for minutes to hours.
 
Corrected code:
private void NormalizeTime(ref long duration, out TimePeriod timePeriod, int precision)
{
	int tp = (int)TimePeriod.Nanosecond;
	while(duration >= (1 * precision))
	{
		if(tp < (int)TimePeriod.Second)
		{
			duration /= 1000;
			tp++;
		}
		else if (tp < (int)TimePeriod.Hour) 
		{
			duration /= 60;
			tp++;
		}
		else
			break;
	}
	timePeriod = (TimePeriod)tp;
}
 
private void NormalizeHitcount(ref double hitcount, ref TimePeriod timePeriod, int precision)
{
	int tp = (int)timePeriod;
	while(hitcount < (1 * precision))
	{
		if(tp < (int)TimePeriod.Second)
		{
			hitcount *= 1000;
			tp++;
		}
		else if(tp < (int)TimePeriod.Hour)
		{
			hitcount *= 60;
			tp++;
		}
		else
			break;
	}
	timePeriod = (TimePeriod)tp;
}
 
private long TimeToNanoseconds(long duration, TimePeriod timePeriod)
{
	switch(timePeriod)
	{
		case TimePeriod.Microsecond:
		{
			duration *= 1000;
			break;
		}
		case TimePeriod.Millisecond:
		{
			duration *= 1000000;
			break;
		}
		case TimePeriod.Second:
		{
			duration *= 1000000000;
			break;
		}
		case TimePeriod.Minute:
		{
			duration *= 60000000000;
			break;
		}
		case TimePeriod.Hour:
		{
			duration *= 3600000000000;
			break;
		}
	}
	return duration;
}
 

GeneralRe: NormalizeTime not rightmemberAdamSlosarski18-May-04 3:49 
Of course, you're right, i don't know how i omitted this mistake, but i think i was expressed using cut/paste function Smile | :) I will fix NTime to provide correct minutes and hours calculation.
 
Thank you for your engage in bug searching? how did you found it - tracing source code first or using this tool on ready application.
 
Could you tell me your scenario, when do you use it this tool? Is this tool helpful or what would you like to NTime do more for unit testing?
 
Again, Thanks for this comment

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!
GeneralRe: NormalizeTime not rightmemberAdamSlosarski18-May-04 4:20 
I have to reply again,
It is currently also not so clear after your fix, the line:
 
while(hitcount < (1 * precision))
 
assumes that the time base (precision) is number of power to 10 (10^N) i.e. 1000 or 1000000 but for seconds and minutes there will be (60^N). I think i will correct this all you wrote, it will take me some time to fix, the problem is a little complex - there is many tests to evaluate whether fixed bug is not duplicated in other area.
 
Thanks for engaging in source code

 
Testing your code against performance will keep you running with good scalability and maintenance for years.
NTime.exe - the free tool for real developers of high scalability applications!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130617.1 | Last Updated 31 Mar 2006
Article Copyright 2004 by AdamSlosarski
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid