Class: Benny::Reporters::File

Inherits:
Object
  • Object
show all
Defined in:
lib/benny/reporters/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(path:, env_name:) ⇒ File

Returns a new instance of File.



8
9
10
11
12
13
14
15
16
# File 'lib/benny/reporters/file.rb', line 8

def initialize(path:, env_name:)
  @path = path
  @data = {
    env_name: env_name,
    benchmarks: []
  }

  at_exit { ::File.write(::File.join(@path, "#{Process.pid}.json"), JSON.dump(@data)) }
end

Instance Method Details

#report(benchmark, measure) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/benny/reporters/file.rb', line 18

def report(benchmark, measure)
  raise ArgumentError, "Measure of type #{measure.class} not supported." unless measure.is_a?(Benchmark::Tms)

  @data[:benchmarks] << {
    type: 'Benchmark::Tms',
    name: benchmark.name,
    utime: measure.utime,
    stime: measure.stime,
    total: measure.total
  }
end