views:

251

answers:

2

I have some code that I want to measure the speed of while it runs continuously in automated regression tests. The purpose of this would be to alert me to changes made to the code which have had a negative impact on performance.

In pseudo-code, I want something like this:

cpuTimer.start
runTest
cpuTimer.stop

diff = cpuTimer.getDuration

if diff > prevDiff // Perhaps to within a tolerance
    failTest

I'm looking at ThreadMXBean#getCurrentThreadCpuTime() for this, but the key problem is that the automated tests will be run on a wide range of different developer's pcs, and will be automatically farmed out to test servers with a range of different hardware and capabilities.

Will this work, or will the numbers go awry?

How should this problem be solved? Is there a better way? Is there a standard tool for this sort of caper?

A: 

One approach would be to analyze the standard xml files that are output from the junit running in both maven and ant. These contain all the data you need. Although there are tools to generate reports based on these, I am not aware of any aggregators/watchers.

If you put these in a database table with fields hostname, testname, executiontime and buildNumber you should be able to do most of the things you'd need.

krosenvold
I should have said that I'm not using JUnit. For tedious, horrible technical and historical reasons, the whole system is custom-built.
izb
Switching to junit has become ever so much easier with junit4 ;)
krosenvold
+3  A: 

You might try to look at Perf4J. I haven't used it yet, but it's on my list of things to investigate.

From their homepage:

Perf4J is to System.currentTimeMillis() as log4j is to System.out.println()

The Developer Guide is a nice introduction.

Steve K
We need to do something similar on our project and Perf4J seems to be the best solution.
this really does look cool. has anyone worked with it yet?
Epaga