Last active
October 18, 2015 06:22
-
-
Save tamamu/7aa0492b872f9961eae5 to your computer and use it in GitHub Desktop.
Fibonacci benchmark comparison of C and Common Lisp.
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
#include <stdio.h> | |
int fib(int n){ | |
if(n<2)return n; | |
return fib(n-2) + fib(n-1); | |
} | |
int main(){ | |
printf("%d\n", fib(38)); | |
return 0; | |
} |
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
(declaim (ftype (function (fixnum) fixnum) fib)) | |
(defun fib (n) | |
(declare (optimize (speed 3) (debug 0) (safety 0)) (type fixnum n)) | |
(if (< n 2) | |
n | |
(+ (fib (- n 2)) (fib (1- n))))) | |
(defun main () | |
(print (fib 38))) | |
(declaim (optimize (speed 3) (debug 0) (safety 0))) | |
(defun make-app () | |
#+sbcl (sb-ext:save-lisp-and-die "fib-sbcl" | |
:toplevel #'main | |
:executable t) | |
#+ccl (ccl:save-application "fib-ccl" | |
:toplevel-function #'main | |
:prepend-kernel t)) | |
(make-app) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment