Class: Minitest::BenchSpec (Ruby 2.7.5)
Description: Class : Minitest::BenchSpec - Ruby 2.7.5

### Home Classes Methods

### In Files

- minitest-5.13.0/lib/minitest/benchmark.rb

### Parent

Minitest::Benchmark

### Methods

- ::bench
- ::bench_performance_constant
- ::bench_performance_exponential
- ::bench_performance_linear
- ::bench_performance_logarithmic
- ::bench_performance_power
- ::bench_range

### Files

- History.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- Kernel
- Minitest::AbstractReporter
- Minitest::Assertion
- Minitest::Assertions
- Minitest::BacktraceFilter
- Minitest::BenchSpec
- Minitest::Benchmark
- Minitest::CompositeReporter
- Minitest::Expectations
- Minitest::Guard
- Minitest::Mock
- Minitest::Parallel
- Minitest::Parallel::Executor
- Minitest::PrideIO
- Minitest::PrideLOL
- Minitest::ProgressReporter
- Minitest::Reportable
- Minitest::Result
- Minitest::Skip
- Minitest::Spec
- Minitest::Spec::DSL
- Minitest::Spec::DSL::InstanceMethods
- Minitest::StatisticsReporter
- Minitest::SummaryReporter
- Minitest::Test
- Minitest::Test::LifecycleHooks
- Minitest::UnexpectedError
- Object
- SubThingySpec
- ThingySpec

No matching classes.

# Minitest::BenchSpec

The spec version of `Minitest::Benchmark`.

### Public Class Methods

bench(name, &block) click to toggle source

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-5.13.0/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) click to toggle source

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

                   # File minitest-5.13.0/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) click to toggle source

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

                   # File minitest-5.13.0/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) click to toggle source

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

                   # File minitest-5.13.0/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_performance_logarithmic(name, threshold = 0.99, &work) click to toggle source

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

                   # File minitest-5.13.0/lib/minitest/benchmark.rb, line 432
    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) click to toggle source

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

                   # File minitest-5.13.0/lib/minitest/benchmark.rb, line 447
    def self.bench_performance_power name, threshold = 0.99, &work
      bench name do
        assert_performance_power threshold, &work
      end
    end

bench_range(&block) click to toggle source

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.

                   # File minitest-5.13.0/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