Class: ConsoleUtils::BenchUtils::Chips

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/console_utils/bench_utils/chips.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#resultsObject (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

Returns:

  • (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

.sharedObject

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

#recentObject

Get a recent result


49
50
51
# File 'lib/console_utils/bench_utils/chips.rb', line 49

def recent
  results.last
end

#split!(*args) ⇒ Object

Splits reports to a new context


54
55
56
# File 'lib/console_utils/bench_utils/chips.rb', line 54

def split!(*args)
  Chips.new(__getobj__.split!(*args))
end