File: mean.yml

package info (click to toggle)
ruby-enumerable-statistics 2.0.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,156 kB
  • sloc: ruby: 2,273; ansic: 2,033; javascript: 408; makefile: 8; sh: 4
file content (30 lines) | stat: -rw-r--r-- 541 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
contexts:
  - name: "master"
    prelude: |-
      require 'bundler/setup'
      require 'enumerable/statistics'
prelude: |-
  n = 1000
  ary = Array.new(n) { rand }
benchmark:
  inject: mean = ary.inject(:+) / n.to_f
  while: |-
    i, mean = 0, 0
    while i < n
      mean += ary[i]
      i += 1
    end
    mean /= n.to_f
  pure_ruby: |-
    i, f, c = 0, 0.0, 0.0, 0.0, 0.0
    while i < n
      x = ary[i]
      y = x - c
      t = f + y
      c = (t - f) - y
      f = t

      i += 1
    end
    mean = f / n
  c_ext: mean = ary.mean