-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* benchmark/driver.rb: fix notations.
* benchmark/bm_loop_whileloop.rb: ditto. * benchmark/bm_loop_whileloop2.rb: ditto. * benchmark/bm_app_uri.rb: added. * benchmark/bm_vm1_ivar_set.rb: ditto. * benchmark/bm_so_binary_trees.rb: added from Computer Language Benchmarks Game (http://shootout.alioth.debian.org/). * benchmark/bm_so_fannkuch.rb: ditto. * benchmark/bm_so_mandelbrot.rb: ditto. * benchmark/bm_so_meteor_contest.rb: ditto. * benchmark/bm_so_nbody.rb: ditto. * benchmark/bm_so_nsieve.rb: ditto. * benchmark/bm_so_nsieve_bits.rb: ditto. * benchmark/bm_so_partial_sums.rb: ditto. * benchmark/bm_so_pidigits.rb: ditto. * benchmark/bm_so_spectralnorm.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
- Loading branch information
Showing
16 changed files
with
1,173 additions
and
4 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
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,8 @@ | ||
require 'uri' | ||
|
||
100_000.times{ | ||
uri = URI.parse('http://www.ruby-lang.org') | ||
uri.scheme | ||
uri.host | ||
uri.port | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
i = 0 | ||
while i<30000000 # benchmark loop 1 | ||
i=0 | ||
while i<30_000_000 # benchmark loop 1 | ||
i+=1 | ||
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
i=0 | ||
while i<6000000 # benchmark loop 2 | ||
while i< 6_000_000 # benchmark loop 2 | ||
i+=1 | ||
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,57 @@ | ||
# The Computer Language Shootout Benchmarks | ||
# http://shootout.alioth.debian.org | ||
# | ||
# contributed by Jesse Millikan | ||
|
||
# disable output | ||
def STDOUT.write_ *args | ||
end | ||
|
||
def item_check(tree) | ||
if tree[0] == nil | ||
tree[1] | ||
else | ||
tree[1] + item_check(tree[0]) - item_check(tree[2]) | ||
end | ||
end | ||
|
||
def bottom_up_tree(item, depth) | ||
if depth > 0 | ||
item_item = 2 * item | ||
depth -= 1 | ||
[bottom_up_tree(item_item - 1, depth), item, bottom_up_tree(item_item, depth)] | ||
else | ||
[nil, item, nil] | ||
end | ||
end | ||
|
||
max_depth = 12 # 16 # ARGV[0].to_i | ||
min_depth = 4 | ||
|
||
max_depth = min_depth + 2 if min_depth + 2 > max_depth | ||
|
||
stretch_depth = max_depth + 1 | ||
stretch_tree = bottom_up_tree(0, stretch_depth) | ||
|
||
puts "stretch tree of depth #{stretch_depth}\t check: #{item_check(stretch_tree)}" | ||
stretch_tree = nil | ||
|
||
long_lived_tree = bottom_up_tree(0, max_depth) | ||
|
||
min_depth.step(max_depth + 1, 2) do |depth| | ||
iterations = 2**(max_depth - depth + min_depth) | ||
|
||
check = 0 | ||
|
||
for i in 1..iterations | ||
temp_tree = bottom_up_tree(i, depth) | ||
check += item_check(temp_tree) | ||
|
||
temp_tree = bottom_up_tree(-i, depth) | ||
check += item_check(temp_tree) | ||
end | ||
|
||
puts "#{iterations * 2}\t trees of depth #{depth}\t check: #{check}" | ||
end | ||
|
||
puts "long lived tree of depth #{max_depth}\t check: #{item_check(long_lived_tree)}" |
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,45 @@ | ||
# The Computer Language Shootout | ||
# http://shootout.alioth.debian.org/ | ||
# Contributed by Sokolov Yura | ||
# Modified by Ryan Williams | ||
|
||
def fannkuch(n) | ||
maxFlips, m, r, check = 0, n-1, n, 0 | ||
count = (1..n).to_a | ||
perm = (1..n).to_a | ||
|
||
while true | ||
if check < 30 | ||
puts "#{perm}" | ||
check += 1 | ||
end | ||
|
||
while r != 1 | ||
count[r-1] = r | ||
r -= 1 | ||
end | ||
|
||
if perm[0] != 1 and perm[m] != n | ||
perml = perm.clone #.dup | ||
flips = 0 | ||
while (k = perml.first ) != 1 | ||
perml = perml.slice!(0, k).reverse + perml | ||
flips += 1 | ||
end | ||
maxFlips = flips if flips > maxFlips | ||
end | ||
while true | ||
if r==n then return maxFlips end | ||
perm.insert r,perm.shift | ||
break if (count[r] -= 1) > 0 | ||
r += 1 | ||
end | ||
end | ||
end | ||
|
||
def puts *args | ||
end | ||
|
||
N = 10 # (ARGV[0] || 1).to_i | ||
puts "Pfannkuchen(#{N}) = #{fannkuch(N)}" | ||
|
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,57 @@ | ||
# The Computer Language Benchmarks Game | ||
# http://shootout.alioth.debian.org/ | ||
# | ||
# contributed by Karl von Laudermann | ||
# modified by Jeremy Echols | ||
|
||
size = 600 # ARGV[0].to_i | ||
|
||
puts "P4\n#{size} #{size}" | ||
|
||
ITER = 49 # Iterations - 1 for easy for..in looping | ||
LIMIT_SQUARED = 4.0 # Presquared limit | ||
|
||
byte_acc = 0 | ||
bit_num = 0 | ||
|
||
count_size = size - 1 # Precomputed size for easy for..in looping | ||
|
||
# For..in loops are faster than .upto, .downto, .times, etc. | ||
for y in 0..count_size | ||
for x in 0..count_size | ||
zr = 0.0 | ||
zi = 0.0 | ||
cr = (2.0*x/size)-1.5 | ||
ci = (2.0*y/size)-1.0 | ||
escape = false | ||
|
||
# To make use of the for..in code, we use a dummy variable, | ||
# like one would in C | ||
for dummy in 0..ITER | ||
tr = zr*zr - zi*zi + cr | ||
ti = 2*zr*zi + ci | ||
zr, zi = tr, ti | ||
|
||
if (zr*zr+zi*zi) > LIMIT_SQUARED | ||
escape = true | ||
break | ||
end | ||
end | ||
|
||
byte_acc = (byte_acc << 1) | (escape ? 0b0 : 0b1) | ||
bit_num += 1 | ||
|
||
# Code is very similar for these cases, but using separate blocks | ||
# ensures we skip the shifting when it's unnecessary, which is most cases. | ||
if (bit_num == 8) | ||
print byte_acc.chr | ||
byte_acc = 0 | ||
bit_num = 0 | ||
elsif (x == count_size) | ||
byte_acc <<= (8 - bit_num) | ||
print byte_acc.chr | ||
byte_acc = 0 | ||
bit_num = 0 | ||
end | ||
end | ||
end |
Oops, something went wrong.