Class: Benchable::Benchmark

Inherits:
Object
  • Object
show all
Defined in:
lib/benchable/benchmark.rb

Constant Summary collapse

DEFAULT_WIDTH =
20
BENCHMARK_TYPES =
i[bm bmbm ips memory].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(benchmark_type, options = {}) ⇒ Benchmark

Returns a new instance of Benchmark.

Raises:



12
13
14
15
16
17
# File 'lib/benchable/benchmark.rb', line 12

def initialize(benchmark_type, options = {})
  @benchmark_type = benchmark_type
  @options = options

  raise Error, "Invalid benchmark type '#{benchmark_type}'" unless valid_benchmark_type?
end

Class Method Details

.bench(name, &block) ⇒ Object



23
24
25
# File 'lib/benchable/benchmark.rb', line 23

def self.bench(name, &block)
  define_method(method_name_for(name), &block)
end

.setup(&block) ⇒ Object



19
20
21
# File 'lib/benchable/benchmark.rb', line 19

def self.setup(&block)
  define_method(:setup, &block)
end

Instance Method Details

#casesObject



34
35
36
# File 'lib/benchable/benchmark.rb', line 34

def cases
  public_methods.grep(/\Abench_/)
end

#runObject



29
30
31
32
# File 'lib/benchable/benchmark.rb', line 29

def run
  setup
  run_benchmark
end

#setupObject



27
# File 'lib/benchable/benchmark.rb', line 27

def setup; end