~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to benchmark/bm_so_partial_sums.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
n = 2_500_000 # (ARGV.shift || 1).to_i
 
2
 
 
3
alt = 1.0 ; s0 = s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = 0.0
 
4
 
 
5
1.upto(n) do |d|
 
6
  d = d.to_f ; d2 = d * d ; d3 = d2 * d ; ds = Math.sin(d) ; dc = Math.cos(d)
 
7
 
 
8
  s0 += (2.0 / 3.0) ** (d - 1.0)
 
9
  s1 += 1.0 / Math.sqrt(d)
 
10
  s2 += 1.0 / (d * (d + 1.0))
 
11
  s3 += 1.0 / (d3 * ds * ds)
 
12
  s4 += 1.0 / (d3 * dc * dc)
 
13
  s5 += 1.0 / d
 
14
  s6 += 1.0 / d2
 
15
  s7 += alt / d
 
16
  s8 += alt / (2.0 * d - 1.0)
 
17
 
 
18
  alt = -alt
 
19
end
 
20
 
 
21
if false
 
22
  printf("%.9f\t(2/3)^k\n", s0)
 
23
  printf("%.9f\tk^-0.5\n", s1)
 
24
  printf("%.9f\t1/k(k+1)\n", s2)
 
25
  printf("%.9f\tFlint Hills\n", s3)
 
26
  printf("%.9f\tCookson Hills\n", s4)
 
27
  printf("%.9f\tHarmonic\n", s5)
 
28
  printf("%.9f\tRiemann Zeta\n", s6)
 
29
  printf("%.9f\tAlternating Harmonic\n", s7)
 
30
  printf("%.9f\tGregory\n", s8)
 
31
end