Skip to content

Instantly share code, notes, and snippets.

@g000001
Created October 31, 2013 15:20
Show Gist options
  • Save g000001/7251534 to your computer and use it in GitHub Desktop.
Save g000001/7251534 to your computer and use it in GitHub Desktop.
(defun fib (n)
(declare (optimize (debug 0) (safety 0) (space 0) (speed 3))
(fixnum n))
(labels ((fib (n)
(if (< n 2)
n
(let* ((fib/n-2
(let ((n (- n 2)))
(if (< n 2)
n
(the fixnum
(+ (fib (1- n))
(fib (- n 2)))))))
(fib/n-1
(let ((n (- n 1)))
(if (< n 2)
n
(the fixnum
(+ fib/n-2
(fib (- n 2))))))))
(the fixnum (+ fib/n-1
fib/n-2))))))
(declare (ftype (function (fixnum) fixnum) fib)
(inline fib))
(fib n)))
(fib 35)
;=> 9227465
#|------------------------------------------------------------|
Evaluation took:
0.001 seconds of real time
0.000000 seconds of total run time (0.000000 user, 0.000000 system)
0.00% CPU
1,439,217 processor cycles
0 bytes consed
Intel(R) Core(TM)2 Duo CPU P8600 @ 2.40GHz
|------------------------------------------------------------|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment