Created
September 21, 2014 13:45
-
-
Save eccyan/f21295ac3ed0b2012beb to your computer and use it in GitHub Desktop.
ruby-llvm sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ✗ LD_LIBRARY_PATH="`llvm-config --libdir`" bundle exec ruby samples/factorial.rb 1 | |
| ; ModuleID = 'Factorial' | |
| define i32 @fac(i32 %n) { | |
| entry: | |
| %test = icmp eq i32 %n, 1 | |
| br i1 %test, label %result, label %recur | |
| recur: ; preds = %entry | |
| %n-1 = sub i32 %n, 1 | |
| %"fac(n-1)" = call i32 @fac(i32 %n-1) | |
| %"n*fac(n-1)" = mul i32 %n, %"fac(n-1)" | |
| br label %result | |
| result: ; preds = %recur, %entry | |
| %fac = phi i32 [ 1, %entry ], [ %"n*fac(n-1)", %recur ] | |
| ret i32 %fac | |
| } | |
| Times show factorial execution times in milliseconds. Both for llvm and ruby iterative and recusive algorithms | |
| Num llvm rec recursive iterative arrar iter. | |
| 20 0.02 0.002 0.001 0.003 | |
| 50 0.031 0.017 0.015 0.009 | |
| 100 0.022 0.032 0.038 0.026 | |
| 200 0.022 0.082 0.078 0.101 | |
| 500 0.026 0.271 0.285 0.255 | |
| 1000 0.034 0.752 0.719 0.666 | |
| 2000 0.046 2.264 2.407 2.286 | |
| 5000 0.094 19.164 24.753 9.305 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment