Class: Benchable::Benchmark
- Inherits:
-
Object
- Object
- Benchable::Benchmark
- Defined in:
- lib/benchable/benchmark.rb
Overview
Main class to perform benchmarks.
Use the method Benchable.bench to declare a benchmark.
Constant Summary collapse
- DEFAULT_WIDTH =
20
- BENCHMARK_TYPES =
%i[bm bmbm ips memory].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #cases ⇒ Object
-
#initialize(benchmark_type, **options) ⇒ Benchmark
constructor
A new instance of Benchmark.
- #run ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(benchmark_type, **options) ⇒ Benchmark
Returns a new instance of Benchmark.
15 16 17 18 19 20 |
# File 'lib/benchable/benchmark.rb', line 15 def initialize(benchmark_type, **) @benchmark_type = benchmark_type @options = raise Error, "Invalid benchmark type '#{benchmark_type}'" unless valid_benchmark_type? end |
Class Method Details
.bench(name, &block) ⇒ Object
26 27 28 |
# File 'lib/benchable/benchmark.rb', line 26 def self.bench(name, &block) define_method(method_name_for(name), &block) end |
.setup(&block) ⇒ Object
22 23 24 |
# File 'lib/benchable/benchmark.rb', line 22 def self.setup(&block) define_method(:setup, &block) end |
Instance Method Details
#cases ⇒ Object
38 39 40 |
# File 'lib/benchable/benchmark.rb', line 38 def cases public_methods.grep(/\Abench_/) end |
#run ⇒ Object
33 34 35 36 |
# File 'lib/benchable/benchmark.rb', line 33 def run setup run_benchmark end |
#setup ⇒ Object
30 31 |
# File 'lib/benchable/benchmark.rb', line 30 def setup end |