Profiling unit tests

We already have a license for ANTS and for our day-to-day profiling we’re pretty happy with it.

However what we are interested in is profiling of unit tests on an integration server. So for instance we use TeamCity/Nunit and we’d like to be able to run unit tests to highlight a block of code and have the unit test fail if the number of cpu cycles for the block of code increases by more than x percent.

So for example:

[Test]
Void PerformanceUnitTest1()
{
//setup code

SpeedTrace.startprofiling();

For(int i=0; I < 10000000; i++
{
Console.write(“hello world”);
}
SpeedTrace.stopprofiling();

long numberOfCPUCycles = SpeedTrace.GetCyles();

Assert.(500000*1.2 > numberOfCPUCycles); // took more than the 500,000 cpu cycles plus 20%
}

If we could do something like this to help automate our profiling it would be very useful to us.

Comments

  • Hello,

    The way you would have to currently approach this would be to have a build step where you run a process for the command line profiler (available in APP Pro) that profiles the nunit command line runner and provide the arguments to the nunit runner for the assembly to process.
    Provide the Profilers with command line arguments to profile child processes and output the results to an xml file.

    Then assert on the content of the xml file for the particular methods running values.

    Edit: also see this support item - http://www.red-gate.com/SupportCenter/c ... 0708000125
    Dene Boulton
    Red Gate
Sign In or Register to comment.