File: sum.yml

package info (click to toggle)
ruby-enumerable-statistics 2.0.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,148 kB
  • sloc: ruby: 2,270; ansic: 2,031; javascript: 408; makefile: 8; sh: 4
file content (29 lines) | stat: -rw-r--r-- 501 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
contexts:
  - name: "master"
    prelude: |-
      require 'bundler/setup'
      require 'enumerable/statistics'
prelude: |-
  n = 1000
  ary = Array.new(n) { rand }
benchmark:
  inject: sum = ary.inject(:+)
  while: |-
    i, sum = 0, 0
    while i < n
      sum += ary[i]
      i += 1
    end
  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
    sum = f
  sum: sum = ary.sum