Class: DerailedBenchmarks::StatsForFile

Inherits:
Object
  • Object
show all
Defined in:
lib/derailed_benchmarks/stats_for_file.rb

Overview

A class for reading in benchmark results and converting them to numbers for comparison

Example:

puts `cat muhfile.bench.txt`

  9.590142   0.831269  10.457801 ( 10.0)
  9.836019   0.837319  10.728024 ( 11.0)

x = StatsForFile.new(name: "muhcommit", file: "muhfile.bench.txt", desc: "I made it faster", time: Time.now)
x.values  #=> [11.437769, 11.792425]
x.average # => 10.5
x.name    # => "muhfile"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, name:, desc: "", time:, short_sha: nil) ⇒ StatsForFile

Returns a new instance of StatsForFile.



21
22
23
24
25
26
27
28
29
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 21

def initialize(file:, name:, desc: "", time: , short_sha: nil)
  @file = Pathname.new(file)
  FileUtils.touch(@file)

  @name = name
  @desc = desc
  @time = time
  @short_sha = short_sha
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



19
20
21
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19

def name
  @name
end

#short_shaObject (readonly)

Returns the value of attribute short_sha.



19
20
21
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19

def short_sha
  @short_sha
end

#timeObject (readonly)

Returns the value of attribute time.



19
20
21
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19

def time
  @time
end

#valuesObject (readonly)

Returns the value of attribute values.



19
20
21
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 19

def values
  @values
end

Instance Method Details

#averageObject



47
48
49
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 47

def average
  @average.to_f
end

#callObject



31
32
33
34
35
36
37
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 31

def call
  load_file!
  return if values.empty?

  @median = (values[(values.length - 1) / 2] + values[values.length/ 2]) / 2.0
  @average = values.inject(:+) / values.length
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 39

def empty?
  values.empty?
end

#medianObject



43
44
45
# File 'lib/derailed_benchmarks/stats_for_file.rb', line 43

def median
  @median.to_f
end