| djberg96 ( @ 2005-10-30 09:36:00 |
| Current mood: | awake |
BenchUnit?
I'm in the process of writing a hefty benchmark suite for Ruby. I'm doing this for several reasons - so we have a baseline to compare minor (or major) releases against each other, heavy iteration testing, checks for pathological slowdowns, and as a way to spot code we could optimize.
One of the things I'm discovering is that I'm constantly having to create a fresh instance of some object, then benchmarking against that object, to make sure I've got a "clean" object that wasn't affected by one of the other benchmarks. Sounds just like the scenario we have in testing, doesn't it? It's also annoying to constantly wrap everything in "MAX.times{ code_to_benchmark }".
It would be nice to have something like this:
class BC_Array < Bench::Unit::BenchCase
def setup
@max = 100000
@array = [1, "two", nil, true, 3]
end
def bench_clear
@array.clear
end
def bench_concat
@array.concat([1,2,3])
end
def teardown
@array = nil
end
end
In this theoretical code, every method that started with "bench_" would be run as a benchmark, iterating "@max" times automatically, getting a new "@array" within each benchmark. I suppose you could create "bench runners" to format output and such as well.
So, who needs a task?