Skip to content

Instantly share code, notes, and snippets.

@tamamu
Last active October 18, 2015 06:22
Show Gist options
  • Save tamamu/7aa0492b872f9961eae5 to your computer and use it in GitHub Desktop.
Save tamamu/7aa0492b872f9961eae5 to your computer and use it in GitHub Desktop.
Fibonacci benchmark comparison of C and Common Lisp.
#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;
}
(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