File: README
benchmark_unit
Machine-independent benchmark assertions for your unit tests.
License
Copyright 2008 Cloudburst, LLC. Licensed under the AFL 3. See the included LICENSE file.
The public certificate for the gem is here.
If you use this software, please make a donation, or recommend Evan at Working with Rails.
Features
- Test::Unit-compatible
- machine-independent measurement units
Installation
sudo gem install benchmark_unit
Usage
First, require the library. Then, in a regular Test::Unit::TestCase, call either assert_faster or assert_slower. Pass a number of RubySeconds and a block to benchmark.
require 'benchmark/unit'
class MyTest < Test::Unit::TestCase
def test_speed_of_critical_method
assert_faster(3) do
MyCriticalMethod("data")
end
end
end
You do not have to manually run the block multiple times; the library does that for you.
To find how many RubySeconds to start with, just omit the argument to the assert_faster or assert_slower call. The test will fail and report how long your block took. Add a little bit and use that as your initial failure point.
See Benchmark::RubySeconds for more details.
Note that you can‘t reliably test Benchmark::Unit with sleep calls. sleep triggers a context switch and doesn‘t count against the system time of the method.
Reporting problems
The support forum is here.
Patches and contributions are very welcome. Please note that contributors are required to assign copyright for their additions to Cloudburst, LLC.