Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'rubygems'
require 'inline'
class MyTestInC
inline do |builder|
builder.c <<-EOF
long factorial(int max) {
int i=max, result=1;
while (i >= 2) {
result *= i--;
}
return result;
}
EOF
end
end
class MyTestInRuby
def factorial(n)
return 1 if n == 0
n * factorial(n-1)
end
end
def time_test(test_name, times=10000, &block)
start = Time.now
if block_given?
times.times { yield }
puts "Called block '#{test_name}' #{times} times in #{Time.now - start} seconds"
end
end
c = MyTestInC.new
r = MyTestInRuby.new
time_test "With C Extension" do
c.factorial(10)
end
time_test "In Pure Ruby" do
r.factorial(10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.