A problem I'm having at work right now is that I need a simple benchmarking tool across multiple libraries. The FeedParser is a good example because I want to link to the code there but also in our internal code which also has some intregration with our DB.
This way I can look at a histograph of operations per second and how all of the systems interact.
I wrote a simple prototype and here's the javadoc:
/** * Benchmark that allows cheap and lightweight "benchmarking" (go figure) of * arbitrary code. All you have to do is call inc() every time a method * completes which will then increment the benchmark and perform any operations * necessary to maintain the benchmark. * * This class is lightweight (only requires a hashmap entry, and (24 bytes per * benchmark) of storage with no external requirements. This class is also * threadsafe so if you need to call this from multithreaded code to benchmark * the you'll be ok. * * The benchmark is maintained as number of inc()s per minute. This can be any * type of operation you want. Technically the interval can be longer than a * minute but we will end up with stale data. That's the tradeoff with this * type of benchmark. Its cheap and easy to maintain but anything more than 60 * seconds worth of data and you'll end up with a stale benchmark. * * Internally we use an incremented value which is accumulated and reset ever 60 * seconds. When we reset the benchmark we reset the current value so that we * can start accumulating again. * * @author <a href="mailto:[EMAIL PROTECTED]">Kevin Burton</a> * @version $Id: Adler32.java,v 1.4 2004/05/21 22:21:32 burton Exp $ */
Now it dawned on me that if this was OSS that it could be used similar to log4j. One could integrate this with log4j to have it log its operations every 60 seconds so that you could enable logging of benchmark information if you're trying to debug performance.
It would also allow constructs such as:
Benchmark benchmark = Benchmark.getBenchmark( Foo.class );
try {
benchmark.enter();
//perform some slow complicated operation
} finally { benchmark.exit(); }
Then I could enable the benchmarks logging at runtime. Since the benchmarks only require 100 bytes or so (with hashmap overhead) one could add benchmarking anywhere they wanted without much of a VM overhead.
Anyway... my NYE resolution was to make sure all of my util code becomes OSS ;).. Any interest in having this move into the sandbox or collaborating in this somewhere?
Assuming there's interest that is. I need it for work so I'll probably work on a proof of concept ASAP ...
Kevin
--
Use Rojo (RSS/Atom aggregator). Visit http://rojo.com. Ask me for an invite! Also see irc.freenode.net #rojo if you want to chat.
Rojo is Hiring! - http://www.rojonetworks.com/JobsAtRojo.html
If you're interested in RSS, Weblogs, Social Networking, etc... then you should work for Rojo! If you recommend someone and we hire them you'll get a free iPod!
Kevin A. Burton, Location - San Francisco, CA
AIM/YIM - sfburtonator, Web - http://peerfear.org/
GPG fingerprint: 5FB2 F3E2 760E 70A8 6174 D393 E84D 8D04 99F1 4412
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]