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::SETUP_METHODS, Test::TEARDOWN_METHODS

Constants included from Reportable

Reportable::BASE_DIR

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 Runnable

#assertions, #failures, #metadata, #time

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, #class_name, i_suck_and_my_tests_are_order_dependent!, make_my_diffs_pretty!, #neuter_exception, #new_exception, parallelize_me!, #run, runnable_methods, #sanitize_exception

Methods included from Guard

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

Methods included from Test::LifecycleHooks

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

Methods included from Reportable

#class_name, #error?, #location, #passed?, #result_code, #skipped?

Methods included from Assertions

#_synchronize, #_where, #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_path_exists, #assert_pattern, #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, #fail_after, #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_path_exists, #refute_pattern, #refute_predicate, #refute_respond_to, #refute_same, #skip, #skip_until, #skipped?, #things_to_diff

Methods inherited from Runnable

#failure, inherited, #initialize, #marshal_dump, #marshal_load, #metadata?, methods_matching, #name, #name=, on_signal, #passed?, reset, #result_code, #run, run, run_one_method, runnable_methods, runnables, #skipped?, test_order, #time_it, 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.



355
356
357
# File '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) ⇒ 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


399
400
401
402
403
# File '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) ⇒ 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


414
415
416
417
418
# File '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) ⇒ 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


384
385
386
387
388
# File '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) ⇒ Object

Create a benchmark that verifies that the performance is logarithmic.

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


429
430
431
432
433
# File '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) ⇒ Object

Create a benchmark that verifies that the performance is power.

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


444
445
446
447
448
# File '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) ⇒ 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.



368
369
370
371
372
373
# File '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