Class: BenchmarkInterface::BenchmarkSet
- Inherits:
-
Object
- Object
- BenchmarkInterface::BenchmarkSet
- Defined in:
- lib/benchmark-interface/benchmark-set.rb
Constant Summary collapse
- @@current =
nil
Instance Attribute Summary collapse
-
#iterations ⇒ Object
readonly
Returns the value of attribute iterations.
Class Method Summary collapse
Instance Method Summary collapse
- #benchmark(name) ⇒ Object
- #benchmarks(names = nil) ⇒ Object
- #implicit_name ⇒ Object
-
#initialize ⇒ BenchmarkSet
constructor
A new instance of BenchmarkSet.
- #load_benchmarks(path) ⇒ Object
- #load_mri_benchmarks(path, options) ⇒ Object
- #prepare ⇒ Object
- #register(name, code) ⇒ Object
Constructor Details
#initialize ⇒ BenchmarkSet
Returns a new instance of BenchmarkSet.
14 15 16 17 18 19 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 14 def initialize @benchmarks = [] @counter = 0 @@current = self @iterations = 1 end |
Instance Attribute Details
#iterations ⇒ Object (readonly)
Returns the value of attribute iterations.
12 13 14 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 12 def iterations @iterations end |
Class Method Details
.current ⇒ Object
80 81 82 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 80 def self.current @@current end |
Instance Method Details
#benchmark(name) ⇒ Object
74 75 76 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 74 def benchmark(name) benchmarks([name]).first end |
#benchmarks(names = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 66 def benchmarks(names=nil) if names @benchmarks.select { |b| names.include?(b.name) } else @benchmarks end end |
#implicit_name ⇒ Object
38 39 40 41 42 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 38 def implicit_name file = File.basename(@path, '.rb') @counter += 1 "#{file}:#{@counter}" end |
#load_benchmarks(path) ⇒ Object
21 22 23 24 25 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 21 def load_benchmarks(path) @path = path @@current = self load(path) end |
#load_mri_benchmarks(path, options) ⇒ Object
27 28 29 30 31 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 27 def load_mri_benchmarks(path, ) @path = path @@current = self Frontends::MRI.load_mri path, end |
#prepare ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/benchmark-interface/benchmark-set.rb', line 44 def prepare # Don't give benchmarks line numbers if there's only one if @benchmarks.size == 1 @benchmarks.first.remove_line_numbers end # Give benchmarks iterations if needed if @benchmarks.any?(&:needs_iterating?) iterations = @benchmarks.map(&:iterations_for_one_second).min puts "This benchmark set contains blocks that want a number of iterations - running all iterations #{iterations} times" @benchmarks.each do |b| b.iterate iterations end @iterations = iterations end end |