I'm presenting at a conference and interested in showing benchmarks between a bunch of different languages (including some Lisp, Scheme, Python, C, etc).
Code: Select all
; sbcl lisp version by mandeep singh
(declaim (optimize (speed 3)))
(defconstant +BAILOUT+ 16)
(defconstant +MAX-ITERATIONS+ 1000)
(defun mandelbrot (x y)
(declare (type single-float x y))
(let ((cr (- y 0.5))
(ci x)
(zi 0.0)
(zr 0.0))
(declare (type single-float cr ci zi zr))
(do ((i 0 (incf i)))
(nil)
(let* ((temp (the single-float (* zr zi)))
(zr2 (the single-float (* zr zr)))
(zi2 (the single-float (* zi zi))))
(declare (type single-float temp zr2 zi2)
(type fixnum i))
(setq zr (the single-float (+ (- zr2 zi2) cr)))
(setq zi (the single-float (+ temp temp ci)))
(if (> (the single-float (+ zi2 zr2)) +BAILOUT+)
(return-from mandelbrot i))
(if (> i +MAX-ITERATIONS+)
(return-from mandelbrot 0))))))
(defun main ()
(let ((tstart)
(tfinish))
(setq tstart (get-internal-real-time))
(do ((y -39 (incf y)))
((= (the fixnum y) 39))
(format t "~%")
(do ((x -39 (incf x)))
((= (the fixnum x) 39))
(let ((i (mandelbrot (the single-float (/ x 40.0))
(the single-float (/ y 40.0)))))
(declare (type fixnum i x y))
(if (zerop i)
(format t "*")
(format t " ")))))
(format t "~%")
(setq tfinish (get-internal-real-time))
(format t "SBCL Elapsed ~,2F~%"
(coerce (/ (- tfinish tstart) internal-time-units-per-second) 'float))))
(progn
(main)
(quit))