Class: Vedeu::Logging::Debug::IPS

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/logging/ips.rb

Overview

Provide wrapper for ‘benchmark-ips’ gem.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVedeu::Logging::Debug::IPS

Returns a new instance of Vedeu::Logging::Debug::IPS.



19
20
21
22
23
24
25
# File 'lib/vedeu/logging/ips.rb', line 19

def initialize
  @old_stdout = $stdout
  $stdout     = StringIO.new
  @samples    = {}
  @benchmark  = Benchmark::IPS::Job.new
  @count      = 0
end

Instance Attribute Details

#benchmarkObject

Returns the value of attribute benchmark.



14
15
16
# File 'lib/vedeu/logging/ips.rb', line 14

def benchmark
  @benchmark
end

#samplesObject

Returns the value of attribute samples.



13
14
15
# File 'lib/vedeu/logging/ips.rb', line 13

def samples
  @samples
end

Instance Method Details

#add_item(label = '', &blk) ⇒ void

This method returns an undefined value.

Parameters:

  • label (String) (defaults to: '')


29
30
31
32
33
34
# File 'lib/vedeu/logging/ips.rb', line 29

def add_item(label = '', &blk)
  samples[label] = blk
  @count += 1

  benchmark.item(label, &blk)
end

#execute!void

This method returns an undefined value.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vedeu/logging/ips.rb', line 37

def execute!
  benchmark.compare!
  benchmark.run_warmup
  benchmark.run

  $stdout.sync = true
  benchmark.run_comparison
  benchmark.full_report

  Vedeu.log(type: :debug, message: "IPS:\n#{$stdout.string}".freeze)
  $stdout = @old_stdout

  Vedeu.log(type: :debug, message: "Running: #{key}".freeze)
  samples[key].call
end

#keyvoid (private)

This method returns an undefined value.



56
57
58
# File 'lib/vedeu/logging/ips.rb', line 56

def key
  @key ||= samples.keys.sample
end