Missing MethodTimer.computeTotalTime() in Implementation Patterns

While preparing a review of Kent Beck’s Implementation Patterns book for stacktrace.it I stumbled upon a missing detail in Appendix A (Performance Measurement): where is the implementation of MethodTimer.computeTotalTime()?

I didn’t pay much attention while reading the book: Appendix A is one of my favourite chapters because you can finally see what Beck means in practice, but I haven’t really considered all the implementation details, only the overall philosophy. For the review I decided to go deeper and I couldn’t really understand what happened to MethodTimer.computeTotalTime(). In addition, until you realize how that method should look like, maybe you find yourself in troubles trying to fully grasp the design. I certainly did. Google didn’t help (I guess that Beck for whatever reason didn’t want to publish the code), so I did it by myself.

 private long computeTotalTime() throws Exception {
 	long start = System.nanoTime();
 	for (int i = 0; i < iterations; i++)
 		method.invoke(instance, new Object[0]);
 	return System.nanoTime() - start;
 }

This is not rocket science of course, but I had a few false starts before getting it (also because I made a few mistakes copying the code from the book and I was misled by the results). Hope it can help you as well.

Tags: , , , , , ,

One Response to “Missing MethodTimer.computeTotalTime() in Implementation Patterns”

  1. Stein Erik Berget Says:

    Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: