BasicObject
GNU Linux
AO render benchmark Original program (C) Syoyo Fujita in Javascript (and other languages)
http://lucille.atso-net.jp/blog/?p=642 http://lucille.atso-net.jp/blog/?p=711
Ruby(yarv2llvm) version by Hideki Miura mruby version by Hideki Miura
Mac OS X MPIDE_PATH = ‘/Applications/mpide.app/Contents/Resources/Java’ GNU Linux
Performs fuzzy check for equality on methods returning floats on the basis of the Math::TOLERANCE constant.
# File mrbgems/mruby-math/test/math.rb, line 7
def check_float(a, b)
tolerance = Math::TOLERANCE
a = a.to_f
b = b.to_f
if a.finite? and b.finite?
(a-b).abs < tolerance
else
true
end
end
# File benchmark/ao-render.rb, line 172
def clamp(f)
i = f * 255.5
if i > 255.0 then
i = 255.0
end
if i < 0.0 then
i = 0.0
end
i.to_i
end
Fib 39
# File benchmark/fib39.rb, line 3
def fib n
return n if n < 2
fib(n-2) + fib(n-1)
end
# File benchmark/ao-render.rb, line 183
def otherBasis(basis, n)
basis[2] = Vec.new(n.x, n.y, n.z)
basis[1] = Vec.new(0.0, 0.0, 0.0)
if n.x < 0.6 and n.x > -0.6 then
basis[1].x = 1.0
elsif n.y < 0.6 and n.y > -0.6 then
basis[1].y = 1.0
elsif n.z < 0.6 and n.z > -0.6 then
basis[1].z = 1.0
else
basis[1].x = 1.0
end
basis[0] = basis[1].vcross(basis[2])
basis[0] = basis[0].vnormalize
basis[1] = basis[2].vcross(basis[0])
basis[1] = basis[1].vnormalize
end
# File benchmark/bm_so_lists.rb, line 6
def test_lists()
# create a list of integers (Li1) from 1 to SIZE
li1 = (1..SIZE).to_a
# copy the list to li2 (not by individual items)
li2 = li1.dup
# remove each individual item from left side of li2 and
# append to right side of li3 (preserving order)
li3 = Array.new
while (not li2.empty?)
li3.push(li2.shift)
end
# li2 must now be empty
# remove each individual item from right side of li3 and
# append to right side of li2 (reversing list)
while (not li3.empty?)
li2.push(li3.pop)
end
# li3 must now be empty
# reverse li1 in place
li1.reverse!
# check that first item is now SIZE
if li1[0] != SIZE then
p "not SIZE"
0
else
# compare li1 and li2 for equality
if li1 != li2 then
return(0)
else
# return the length of the list
li1.length
end
end
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.