Class: Bixby::Bench::Sample

Inherits:
Object
  • Object
show all
Defined in:
lib/bixby/bench/sample.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, block, sample_size, memory) ⇒ Sample

Returns a new instance of Sample.



8
9
10
11
12
13
# File 'lib/bixby/bench/sample.rb', line 8

def initialize(label, block, sample_size, memory)
  @label       = label
  @block       = block
  @sample_size = sample_size
  @memory      = memory
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/bixby/bench/sample.rb', line 6

def block
  @block
end

#labelObject (readonly)

Returns the value of attribute label.



6
7
8
# File 'lib/bixby/bench/sample.rb', line 6

def label
  @label
end

Instance Method Details

#callObject



15
16
17
# File 'lib/bixby/bench/sample.rb', line 15

def call
  @block.call
end

#measureObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/bixby/bench/sample.rb', line 19

def measure
  report = Report.new
  report.tms = Benchmark.measure { @sample_size.times { self.call } }

  if @memory then
    report.allocation_stats = AllocationStats.new(burn: 5).trace { self.call }
  end

  return report
end