Class: Minitest::BenchSpec

Inherits:
Benchmark show all
Extended by:
Spec::DSL
Defined in:
lib/minitest/benchmark.rb

Overview

The spec version of Minitest::Benchmark.

Constant Summary

Constants included from Spec::DSL

Spec::DSL::TYPES

Constants inherited from Test

Test::PASSTHROUGH_EXCEPTIONS, Test::TEARDOWN_METHODS

Constants included from Assertions

Assertions::E, Assertions::UNDEFINED

Constants inherited from Runnable

Runnable::SIGNALS

Instance Attribute Summary

Attributes included from Spec::DSL

#desc

Attributes inherited from Test

#time

Attributes inherited from Runnable

#assertions, #failures

Class Method Summary collapse

Methods included from Spec::DSL

after, before, children, create, describe_stack, extended, it, let, name, nuke_test_methods!, register_spec_type, spec_type, subject, to_s

Methods inherited from Benchmark

#assert_performance, #assert_performance_constant, #assert_performance_exponential, #assert_performance_linear, #assert_performance_logarithmic, #assert_performance_power, bench_exp, bench_linear, #fit_error, #fit_exponential, #fit_linear, #fit_logarithmic, #fit_power, #io, io, run, runnable_methods, #sigma, #validation_for_fit

Methods inherited from Test

#capture_exceptions, #error?, i_suck_and_my_tests_are_order_dependent!, #location, make_my_diffs_pretty!, #marshal_dump, #marshal_load, parallelize_me!, #passed?, #result_code, #run, runnable_methods, #skipped?, test_order, #time_it, #to_s, #with_info_handler

Methods included from Guard

#jruby?, #maglev?, #mri?, #rubinius?, #windows?

Methods included from Test::LifecycleHooks

#after_setup, #after_teardown, #before_setup, #before_teardown, #setup, #teardown

Methods included from Assertions

#_synchronize, #assert, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_mock, #assert_nil, #assert_operator, #assert_output, #assert_predicate, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_silent, #assert_throws, #capture_io, #capture_subprocess_io, #diff, diff, diff=, #exception_details, #flunk, #message, #mu_pp, #mu_pp_for_diff, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_predicate, #refute_respond_to, #refute_same, #skip, #skipped?

Methods inherited from Runnable

#failure, inherited, #initialize, #marshal_dump, #marshal_load, methods_matching, #name, #name=, on_signal, #passed?, reset, #result_code, run, #run, run_one_method, runnable_methods, runnables, #skipped?, with_info_handler

Constructor Details

This class inherits a constructor from Minitest::Runnable

Class Method Details

.bench(name, &block) ⇒ 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.



357
358
359
# File 'lib/minitest/benchmark.rb', line 357

def self.bench name, &block
  define_method "bench_#{name.gsub(/\W+/, "_")}", &block
end

.bench_performance_constant(name, threshold = 0.99, &work) ⇒ Object

Create a benchmark that verifies that the performance is constant.

describe "my class Bench" do
  bench_performance_constant "zoom_algorithm!" do |n|
    @obj.zoom_algorithm!(n)
  end
end


401
402
403
404
405
# File 'lib/minitest/benchmark.rb', line 401

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) ⇒ Object

Create a benchmark that verifies that the performance is exponential.

describe "my class Bench" do
  bench_performance_exponential "algorithm" do |n|
    @obj.algorithm(n)
  end
end


416
417
418
419
420
# File 'lib/minitest/benchmark.rb', line 416

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) ⇒ Object

Create a benchmark that verifies that the performance is linear.

describe "my class Bench" do
  bench_performance_linear "fast_algorithm", 0.9999 do |n|
    @obj.fast_algorithm(n)
  end
end


386
387
388
389
390
# File 'lib/minitest/benchmark.rb', line 386

def self.bench_performance_linear name, threshold = 0.99, &work
  bench name do
    assert_performance_linear threshold, &work
  end
end

.bench_range(&block) ⇒ Object

Specifies the ranges used for benchmarking for that class.

bench_range do
  bench_exp(2, 16, 2)
end

See Minitest::Benchmark#bench_range for more details.



370
371
372
373
374
375
# File 'lib/minitest/benchmark.rb', line 370

def self.bench_range &block
  return super unless block

  meta = (class << self; self; end)
  meta.send :define_method, "bench_range", &block
end