class Minitest::BenchSpec
Minitest::Benchmark
的 spec 版本。
公共类方法
bench(name, &block) 点击切换源代码
用于定义一个新的基准测试方法。通常您不会直接使用它,它适用于需要编写新的性能曲线拟合(例如:您需要一个特定的多项式拟合)的人。
有关如何使用此方法的示例,请参见 ::bench_performance_linear
。
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 355 def self.bench name, &block define_method "bench_#{name.gsub(/\W+/, "_")}", &block end
bench_performance_constant(name, threshold = 0.99, &work) 点击切换源代码
创建一个基准测试,验证性能是否为常量。
describe "my class Bench" do bench_performance_constant "zoom_algorithm!" do |n| @obj.zoom_algorithm!(n) end end
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 399 def self.bench_performance_constant name, threshold = 0.99, &work bench name do assert_performance_constant threshold, &work end end
bench_performance_exponential(name, threshold = 0.99, &work) 点击切换源代码
创建一个基准测试,验证性能是否为指数级。
describe "my class Bench" do bench_performance_exponential "algorithm" do |n| @obj.algorithm(n) end end
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 414 def self.bench_performance_exponential name, threshold = 0.99, &work bench name do assert_performance_exponential threshold, &work end end
bench_performance_linear(name, threshold = 0.99, &work) 点击切换源代码
创建一个基准测试,验证性能是否为线性。
describe "my class Bench" do bench_performance_linear "fast_algorithm", 0.9999 do |n| @obj.fast_algorithm(n) end end
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 384 def self.bench_performance_linear name, threshold = 0.99, &work bench name do assert_performance_linear threshold, &work end end
bench_performance_logarithmic(name, threshold = 0.99, &work) 点击切换源代码
创建一个基准测试,验证性能是否为对数级。
describe "my class Bench" do bench_performance_logarithmic "algorithm" do |n| @obj.algorithm(n) end end
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 429 def self.bench_performance_logarithmic name, threshold = 0.99, &work bench name do assert_performance_logarithmic threshold, &work end end
bench_performance_power(name, threshold = 0.99, &work) 点击切换源代码
创建一个基准测试,验证性能是否为幂函数。
describe "my class Bench" do bench_performance_power "algorithm" do |n| @obj.algorithm(n) end end
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 444 def self.bench_performance_power name, threshold = 0.99, &work bench name do assert_performance_power threshold, &work end end
bench_range(&block) 点击切换源代码
为该类指定用于基准测试的范围。
bench_range do bench_exp(2, 16, 2) end
有关更多详细信息,请参见 Minitest::Benchmark#bench_range。
# File minitest-5.25.4/lib/minitest/benchmark.rb, line 368 def self.bench_range &block return super unless block meta = (class << self; self; end) meta.send :define_method, "bench_range", &block end