/usr/share/doc/ruby-inline/examples/demo/fastmath.rb is in ruby-inline 3.12.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | begin require 'rubygems' rescue LoadError end
require 'inline'
class FastMath
def factorial(n)
f = 1
n.downto(2) { |x| f *= x }
return f
end
inline do |builder|
builder.c "
long factorial_c(int max) {
int i=max, result=1;
while (i >= 2) { result *= i--; }
return result;
}"
end
end
math = FastMath.new
if ARGV.empty? then
30000.times do math.factorial(20); end
else
30000.times do math.factorial_c(20); end
end
|