views:

102

answers:

1

Is there a good Java library for taking the legwork out of writing good micro-benchmarks? I'm thinking something which can provide (with a minimum of hassle) provide text (CSV or HTML, take your pick) output of results and maybe graphs summarizing results. Ideally, it should be something that plays nicely with JUnit or equivalent, and should be simple to configure benchmarks with variable parameters.

I've looked at japex, but found it too heavyweight (25 MB of libraries to include?!) and frankly it was just a pain to work with. Virtually nonexistent documentation, mucking about with ant, XML, and paths... etc.

+4  A: 

A few of us from the Google Collections team are in the early days of building something that satisfies your needs. Here's the code to measure how long foo() takes:

public class Benchmark1 extends SimpleBenchmark {
  public void timeFoo(int reps) {
    for (int i = 0; i < reps; i++) {
      foo();
    }
  }
}

Neither the API nor the tool itself is particularly stable. We aren't even ready to receive bug reports or feature requests! If I haven't scared you off yet, I invite you to take Caliper for a spin.

Jesse Wilson
Even in the early days, I can see this is much better than japex. I'll take it for a spin, and probably write my benchmarks to be easily adapted to this when it is completed.Proof (once again) that anything Sun can do, Google's coders can do better in their 20% time?
BobMcGee
it was frustration with japex that first started us down the road of developing caliper. :)
Kevin Bourrillion
I was just about to do the same... makes me glad I asked the question, since your version is more elegant than mine would be. I will still have to adapt things a bit to account for all the different parameters (and maybe format output a bit more for my specific case -- MB/s with variable number of bytes run, rather than specific repetition size). But still, massive time savings! Massive!
BobMcGee