Class: RBM::Benchmarker
- Inherits:
-
Object
- Object
- RBM::Benchmarker
- Defined in:
- lib/rbm/benchmarker.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :times => 1 }
Instance Attribute Summary collapse
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(fragments, options) ⇒ Benchmarker
constructor
A new instance of Benchmarker.
- #run ⇒ Object
Constructor Details
#initialize(fragments, options) ⇒ Benchmarker
Returns a new instance of Benchmarker.
11 12 13 |
# File 'lib/rbm/benchmarker.rb', line 11 def initialize(fragments, ) @fragments, @options = fragments, DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
9 10 11 |
# File 'lib/rbm/benchmarker.rb', line 9 def fragments @fragments end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/rbm/benchmarker.rb', line 9 def @options end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbm/benchmarker.rb', line 15 def run width = fragments.map { |fragment| (fragment[:name] || "").length }.max Benchmark.bm(width) do |bm| fragments.each do |fragment| name = fragment[:name] || "" fragment_name = (fragment[:name] || (@unnamed_fragment ||= "fragment_0").succ!).gsub(/\s+/, "_") object = Object.new binding = object.send(:binding) bm.report(name) do # TODO: figure out how to not eval each loop but still provide a better stack trace eval [:init], binding, "init", 1 if [:init] eval fragment[:prerun], binding, "#{fragment_name}_prerun", 1 if fragment[:prerun] [:times].times { eval fragment[:fragment], binding, fragment_name, 1 } eval fragment[:postrun], binding, "#{fragment_name}_postrun", 1 if fragment[:postrun] eval [:cleanup], binding, "cleanup", 1 if [:cleanup] end end end end |