Just found out about Caliper, and going through the documentation - it looks like a great tool (thanks Kevin and the gang at Google for opensourcing it).
Question. Why isn't there an annotation-based mechanism to define benchmarks for the common use cases? Seems that something like:
public class Foo {
// Foo's actual code, followed by...
@Benchmark
static int timeFoobar(int reps) {
Foo foo = new Foo();
for (int i = 0; i < reps; ++i) foo.bar();
}
}
would save a few lines of code and enhance readability.
We decided to use
timeFoo(int reps)
rather than@Time foo(int reps)
for a few reasons:testFoo()
scheme.import com.google.caliper.Time
time
Foo as Foo. This is easy, it's justmethodName.substring(4)
. If we used annotations we'd end up with more complicated machinery to handle names like@Time timeFoo(int reps)
,@Time benchmarkFoo(int reps)
and@Time foo(int reps)
.That said, we're reconsidering this for Caliper 1.0.