Class: BenchmarkHarness::Collection

Inherits:
Array
  • Object
show all
Defined in:
lib/benchmark_harness/collection.rb

Constant Summary collapse

KEYS =

order corresponds to values in each sample

[:user, :system, :children_user, :children_system, :real]
STATS =
[:mean, :median, :mode, :range, :min, :max, :sum, :standard_deviation, :variance]
STATS_HUMAN =
STATS.collect{|s| s.to_s.sub(/_/, " ").capitalize}

Instance Method Summary collapse

Methods included from Stats

included, #mean, #median, #mode, #range, #standard_deviation, #sum_of_deviations_squared, #variance

Instance Method Details

Formatted output



44
45
46
47
48
49
50
51
52
53
# File 'lib/benchmark_harness/collection.rb', line 44

def print
  label_size = STATS_HUMAN.max{|a, b| a.size <=> b.size}.size
  puts sprintf("%#{label_size}s %d", "Samples:", self.size)
  if self.size > 0
    puts sprintf("%#{label_size}s: %10s %10s %10s %10s %10s", "Displaying", "user", "system", "ch.user", "ch.system", "real")
    STATS_HUMAN.each_with_index do |label, i|
      puts sprintf("%#{label_size}s: %10.4g %10.4g %10.4g %10.4g %10.4g", label, *KEYS.collect{|k| self.send(STATS[i], k)})
    end
  end
end

#reconciledObject

Sorts values into named vectors:

Examples:

=> [1,3,2,3], :system => [0,0,0,1]



12
13
14
15
16
17
18
19
20
21
# File 'lib/benchmark_harness/collection.rb', line 12

def reconciled
  return @reconciled if @reconciled
  @reconciled = Hash.new{|h,k| h[k] = []}
  self.each do |sample|
    KEYS.each_with_index do |key, index|
      @reconciled[key] << sample[index]
    end
  end
  @reconciled
end