Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/railsbench/perf_utils.rb

Overview

some utility methods

Instance Method Summary collapse

Instance Method Details

#index_mapObject



4
5
6
7
8
# File 'lib/railsbench/perf_utils.rb', line 4

def index_map
  res = {}
  each_with_index{|element, index| res[index] = element}
  res
end

#meanObject



20
21
22
# File 'lib/railsbench/perf_utils.rb', line 20

def mean
  sum/length
end

#restrict_to(index_set) ⇒ Object



10
11
12
13
14
# File 'lib/railsbench/perf_utils.rb', line 10

def restrict_to(index_set)
  res = []
  each_with_index{|e,i| res << e if index_set.include?(i)}
  res
end

#stddev(mean = nil) ⇒ Object



24
25
26
27
28
# File 'lib/railsbench/perf_utils.rb', line 24

def stddev(mean=nil)
  mean ||= self.mean
  r = inject(0.0){|r,v| r += (v-mean)*(v-mean) }
  Math.sqrt(r/(length-1))
end

#sumObject



16
17
18
# File 'lib/railsbench/perf_utils.rb', line 16

def sum
  inject(0.0){|r,v| r += v }
end