Class: Easybench::Suite
- Inherits:
-
Object
- Object
- Easybench::Suite
- Defined in:
- lib/easybench.rb
Defined Under Namespace
Classes: DuplicateBenchmark
Instance Attribute Summary collapse
-
#benchmarks ⇒ Object
readonly
Returns the value of attribute benchmarks.
-
#tests ⇒ Object
readonly
Returns the value of attribute tests.
Instance Method Summary collapse
- #add_benchmark(name, options = {}, &block) ⇒ Object (also: #report)
-
#initialize(iterations, &tests) ⇒ Suite
constructor
A new instance of Suite.
- #run(runner = ::Benchmark) ⇒ Object
Constructor Details
#initialize(iterations, &tests) ⇒ Suite
Returns a new instance of Suite.
48 49 50 51 52 |
# File 'lib/easybench.rb', line 48 def initialize(iterations, &tests) @iterations = iterations @tests = tests @benchmarks = [] end |
Instance Attribute Details
#benchmarks ⇒ Object (readonly)
Returns the value of attribute benchmarks.
46 47 48 |
# File 'lib/easybench.rb', line 46 def benchmarks @benchmarks end |
#tests ⇒ Object (readonly)
Returns the value of attribute tests.
45 46 47 |
# File 'lib/easybench.rb', line 45 def tests @tests end |
Instance Method Details
#add_benchmark(name, options = {}, &block) ⇒ Object Also known as: report
54 55 56 57 58 59 60 |
# File 'lib/easybench.rb', line 54 def add_benchmark(name, = {}, &block) if benchmark_defined?(name) raise DuplicateBenchmark, "A benchmark test called '#{name}' has already been defined" else @benchmarks << Easybench::Benchmark.new(name, , &block) end end |
#run(runner = ::Benchmark) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/easybench.rb', line 64 def run(runner = ::Benchmark) @tests.call(self) runner.bm do |interface| @benchmarks.each do |benchmark| interface.report(benchmark.name(indent)) do (benchmark.iterations || @iterations).times(&benchmark.tests) end end end end |