forked from rubinius/rubinius
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add another benchmark and a util script
- Loading branch information
Evan Phoenix
committed
Nov 25, 2009
1 parent
96907cc
commit 599d883
Showing
2 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Profiled: heavy on Bignum ops (+, *, /) | ||
|
||
class PiDigitSpigot | ||
|
||
def initialize() | ||
@z = Transformation.new 1,0,0,1 | ||
@x = Transformation.new 0,0,0,0 | ||
@inverse = Transformation.new 0,0,0,0 | ||
end | ||
|
||
def next! | ||
@y = @z.extract(3) | ||
if safe? @y | ||
@z = produce(@y) | ||
@y | ||
else | ||
@z = consume @x.next!() | ||
next!() | ||
end | ||
end | ||
|
||
def safe?(digit) | ||
digit == @z.extract(4) | ||
end | ||
|
||
def produce(i) | ||
@inverse.qrst(10,-10*i,0,1).compose(@z) | ||
end | ||
|
||
def consume(a) | ||
@z.compose(a) | ||
end | ||
end | ||
|
||
class Transformation | ||
attr_reader :q, :r, :s, :t | ||
def initialize (q, r, s, t) | ||
@q,@r,@s,@t,@k = q,r,s,t,0 | ||
end | ||
|
||
def next!() | ||
@q = @k = @k + 1 | ||
@r = 4 * @k + 2 | ||
@s = 0 | ||
@t = 2 * @k + 1 | ||
self | ||
end | ||
|
||
def extract(j) | ||
(@q * j + @r) / (@s * j + @t) | ||
end | ||
|
||
def compose(a) | ||
self.class.new( @q * a.q, | ||
@q * a.r + r * a.t, | ||
@s * a.q + t * a.s, | ||
@s * a.r + t * a.t | ||
) | ||
end | ||
|
||
def qrst *args | ||
initialize *args | ||
self | ||
end | ||
|
||
|
||
end | ||
|
||
WIDTH = 10 | ||
|
||
def Bench.run | ||
n = 1000 | ||
j = 0 | ||
|
||
digits = PiDigitSpigot.new | ||
|
||
while n > 0 | ||
if n >= WIDTH | ||
WIDTH.times {digits.next!} | ||
j += WIDTH | ||
else | ||
n.times {digits.next!} | ||
# (WIDTH-n).times {print " "} | ||
j += n | ||
end | ||
# puts "\t:"+j.to_s | ||
n -= WIDTH | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'yaml' | ||
|
||
file = ARGV.shift | ||
compare_to = ARGV.shift | ||
|
||
data = YAML.load File.read(file) | ||
|
||
totals = Hash.new { |h,k| h[k] = 0 } | ||
|
||
comp_total = 0 | ||
|
||
data.each do |run| | ||
file = run['file'] | ||
runs = run['runs'] | ||
|
||
unless comp_run = runs.delete(compare_to) | ||
raise "Unable to find: #{compare_to}" | ||
end | ||
|
||
comp = comp_run['median'] | ||
|
||
comp_total += comp | ||
|
||
puts file | ||
puts comp | ||
runs.keys.sort.each do |key| | ||
median = runs[key]['median'] | ||
perc = comp.to_f / median | ||
totals[key] += median | ||
puts " #{key} #{perc} #{median}" | ||
end | ||
|
||
puts | ||
|
||
end | ||
|
||
p comp_total | ||
p totals | ||
|
||
totals.each do |key, val| | ||
puts "#{key} #{comp_total.to_f / val}" | ||
end |