Class: ConsoleUtils::BenchUtils::Chips
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- ConsoleUtils::BenchUtils::Chips
- Defined in:
- lib/console_utils/bench_utils/chips.rb
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Class Method Summary collapse
- .method_missing(meth, *args, &blk) ⇒ Object
- .respond_to_missing?(*args) ⇒ Boolean
-
.shared ⇒ Object
The globally shared
Chips
object.
Instance Method Summary collapse
-
#call(name, &block) ⇒ Object
:call-seq: call(“label”) { …things to bench… }.
-
#compare! ⇒ Object
Executes
Benchmark.ips {|x| ...; x.compare! }
using the given hash of procs as reports and push the result toresults
stack. - #del(*args) ⇒ Object
-
#initialize(reports = nil) ⇒ Chips
constructor
Creates Chips context using a given hash of reports.
-
#recent ⇒ Object
Get a recent result.
-
#split!(*args) ⇒ Object
Splits reports to a new context.
Constructor Details
#initialize(reports = nil) ⇒ Chips
Creates Chips context using a given hash of reports.
23 24 25 26 |
# File 'lib/console_utils/bench_utils/chips.rb', line 23 def initialize(reports = nil) super(reports.to_h) @results = [] end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
20 21 22 |
# File 'lib/console_utils/bench_utils/chips.rb', line 20 def results @results end |
Class Method Details
.method_missing(meth, *args, &blk) ⇒ Object
11 12 13 |
# File 'lib/console_utils/bench_utils/chips.rb', line 11 def method_missing(meth, *args, &blk) shared.respond_to?(meth) ? shared.send(meth, *args, &blk) : super end |
.respond_to_missing?(*args) ⇒ Boolean
15 16 17 |
# File 'lib/console_utils/bench_utils/chips.rb', line 15 def respond_to_missing?(*args) shared.respond_to?(*args) || super end |
.shared ⇒ Object
The globally shared Chips
object
7 8 9 |
# File 'lib/console_utils/bench_utils/chips.rb', line 7 def shared @shared ||= new end |
Instance Method Details
#call(name, &block) ⇒ Object
:call-seq:
call("label") { ...things to bench... }
Adds a labeled report block. The same as x.report(label) { ... }
.
44 45 46 |
# File 'lib/console_utils/bench_utils/chips.rb', line 44 def call(name, &block) self[name] = block.to_proc end |
#compare! ⇒ Object
Executes Benchmark.ips {|x| ...; x.compare! }
using the given hash of procs as reports and push the result to results
stack.
31 32 33 34 35 36 37 38 |
# File 'lib/console_utils/bench_utils/chips.rb', line 31 def compare! results << begin Benchmark.ips do |x| each_pair {|name, proc| x.report(name, &proc) } x.compare! end end end |
#del(*args) ⇒ Object
58 59 60 |
# File 'lib/console_utils/bench_utils/chips.rb', line 58 def del(*args) __getobj__.delete(*args) end |
#recent ⇒ Object
Get a recent result
49 50 51 |
# File 'lib/console_utils/bench_utils/chips.rb', line 49 def recent results.last end |