Sha256: d8b93a97afcae9a39d2842e02b9bf40ac490346f4adf28e7da6396f59cd5a035

Contents?: true

Size: 469 Bytes

Versions: 46

Compression:

Stored size: 469 Bytes

Contents

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

Version data entries

46 entries across 46 versions & 4 rubygems

Version Path
RubyInline-3.14.1 demo/fastmath.rb
RubyInline-3.14.0 demo/fastmath.rb
RubyInline-3.13.0 demo/fastmath.rb
RubyInline-3.12.6 demo/fastmath.rb
RubyInline-3.12.5 demo/fastmath.rb
RubyInlineWithoutZenTest-3.12.4.1 demo/fastmath.rb
RubyInlineWithoutZenTest-3.12.4 demo/fastmath.rb
RubyInline-3.12.4 demo/fastmath.rb
RubyInline-3.12.3 demo/fastmath.rb
RubyInlineWithoutZenTest-3.12.2 demo/fastmath.rb
RubyInline-3.12.2 demo/fastmath.rb
RubyInline-3.12.1 demo/fastmath.rb
RubyInline-3.12.0 demo/fastmath.rb
RubyInline-3.11.4 demo/fastmath.rb
RubyInline-3.11.3 demo/fastmath.rb
RubyInline-3.11.2 demo/fastmath.rb
RubyInline-3.11.1 demo/fastmath.rb
RubyInline-3.11.0 demo/fastmath.rb
RubyInline-3.10.1 demo/fastmath.rb
RubyInline-3.10.0 demo/fastmath.rb