miura1729 / yarv2llvm

This URL has Read+Write access

yarv2llvm / benchmark.rb
c62c3239 » miura1729 2008-12-14 Delete comment and change t... 1 #!/bin/env ruby
2 #
3 # yarv2llvm convert yarv to LLVM and define LLVM executable as Ruby method.
4 #
5 #
6 require 'lib/yarv2llvm'
7
8 if __FILE__ == $0 then
9 require 'benchmark'
10
11 def fib(n)
12 if n < 2 then
13 1
14 else
15 fib(n - 1) + fib(n - 2)
16 end
17 end
18
889f977b » miura1729 2008-12-29 Compile out of method and c... 19 YARV2LLVM::compile(<<EOS, {})
c62c3239 » miura1729 2008-12-14 Delete comment and change t... 20 =begin
21 def fact(n)
22 n
23 end
24 =end
25
26 def llvmfib(n)
27 # fact(3.9)
28 if n < 2 then
29 1
30 else
31 llvmfib(n - 1) + llvmfib(n - 2)
32 end
33 end
34
35 EOS
889f977b » miura1729 2008-12-29 Compile out of method and c... 36
c62c3239 » miura1729 2008-12-14 Delete comment and change t... 37 Benchmark.bm do |x|
38 x.report("Ruby "){ p fib(35)}
39 x.report("llvm "){ p llvmfib(35)}
40 end
41 #p fact(5.0)
42 end # __FILE__ == $0
43