Wednesday, September 03, 2008

Testing Processing Time on a JVM

I think most people would agree that having some unit tests, which ensures that non-functional requirements are met, is a good idea. With processing time people usually use time in order to measure whether a particular function runs within the requirements. However, everybody knows that measuring time is inaccurate, since it varies depending on the machine the tests are running and whether there are other process consuming resources in parallel.

Wouldn't it be cool to just count the atomic operations per thread executed by e.g. the Java VM?
We could than have a reference system, which is used to give each atomic operation a value (e.g. nanoseconds).

Then I would like to write tests like this:

@ExecutesIn(23000)
public void testFoo() {
doStuff("Foo "+" bar");
}

Where the number 23000 is the time it would take to run the code on the reference system. The test would always take the same time, no matter it was run on an x386 machine or a modern multi GHz box.

Questions:
Does anyone know whether such a tool/library/framework already exists?
And if not, do you have any idea of how this could be implemented?