Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
Object
This is used to define a new benchmark method. You usually don’t use this directly and is intended for those needing to write new performance curve fits (eg: you need a specific polynomial fit).
See ::bench_performance_linear for an example of how to use this.
# File minitest/benchmark.rb, line 317
def self.bench name, &block
define_method "bench_#{name.gsub(/\W+/, '_')}", &block
end
Create a benchmark that verifies that the performance is constant.
describe "my class" do bench_performance_constant "zoom_algorithm!" do @obj.zoom_algorithm! end end
# File minitest/benchmark.rb, line 352
def self.bench_performance_constant name, threshold = 0.99, &work
bench name do
assert_performance_constant threshold, &work
end
end
Create a benchmark that verifies that the performance is exponential.
describe "my class" do bench_performance_exponential "algorithm" do @obj.algorithm end end
# File minitest/benchmark.rb, line 367
def self.bench_performance_exponential name, threshold = 0.99, &work
bench name do
assert_performance_exponential threshold, &work
end
end
Create a benchmark that verifies that the performance is linear.
describe "my class" do bench_performance_linear "fast_algorithm", 0.9999 do @obj.fast_algorithm end end
# File minitest/benchmark.rb, line 337
def self.bench_performance_linear name, threshold = 0.99, &work
bench name do
assert_performance_linear threshold, &work
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.