performance measurements

Each table row shows performance measurements for this Lisp SBCL program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
100.500.5021,168821  58% 4% 44% 2%
115.445.4423,216821  1% 0% 100% 0%
1273.4973.5123,208821  1% 0% 100% 0%

Read the ↓ make, command line, and program output logs to see how this program was run.

Read fannkuch-redux benchmark to see what this program should do.

 notes

This is SBCL 1.2.5, an implementation of ANSI Common Lisp.

 fannkuch-redux Lisp SBCL #3 program source code

;;   The Computer Language Benchmarks Game
;;   http://benchmarksgame.alioth.debian.org/
;;;
;;; By Jon Smith (rev 3) added some more declarations.
;;; Tranlated from OCaml implementation by ?, who translated it from
;;; the Scala implementation by Otto Bommer.
;;; 
;;; This is a single core implementation. 
;;; I am sure that this program can be improved upon quite a lot.
;;; Most likely it will involve knowing how sbcl does its optimizations.
;;; As you can see, I simply used fixnums everywhere. There may be a better choice.
;;;
;;; To compile
;;; sbcl --load fannkuch.lisp --eval "(save-lisp-and-die \"fannkuch.core\" :purify t :toplevel (lambda () (main) (quit)))"
;;; To run
;;; sbcl --noinform --core fannkuch.core %A

;(setf *efficiency-note-cost-threshold* 1)
;(setf *efficiency-note-limit* 8)

(declaim (optimize (speed 3) (safety 0) (space 1) (debug 0)))

(defmacro sb (a) `(the fixnum ,a))
(deftype sb () 'fixnum)

(defmacro setlambda(n)
  (declare (type fixnum n))
  (let ((copy (gensym))
	(perm (gensym)))
  `(lambda (,perm ,copy)
     (declare (optimize (speed 3) (safety 0) (space 0) (debug 0))
      (type (simple-array sb (,n)) ,copy ,perm))
     ,@(loop for i of-type fixnum from 0 below n collect
	    `(setf (aref ,copy ,i) (aref ,perm ,i))))))

(defmacro countfliplambda (n)
  (declare (type fixnum n))
  (let ((copy (gensym))
	(c (gensym))
	(z (gensym)))
    `(lambda (,copy &aux (,c 0))
       (declare (optimize (speed 3) (safety 0) (space 0) (debug 0))
		(type sb ,c)
		(type (simple-array sb (,n)) ,copy))
       (let ((,z (aref ,copy 0)))
	 (loop until (= ,z 0) do
	      (progn
		(case ,z 
		  ,@(loop for i of-type sb from 1 to (- n 1) collect
			 `(,i
			   ,@(loop for j of-type sb from 0 to (ash i -1)
				if (not (= j (- i j)))
				collect `(rotatef (aref ,copy ,j) 
						  (aref ,copy ,(- i j)))))))
		(incf ,c)
		(setf ,z (aref ,copy 0)))))
       ,c)))

(defun fannkuch (n)
  (declare (type sb n))
  (let ((csum 0)
	(fmax 0))
    (declare (type sb csum fmax))
    (let ((perm (make-array n :element-type 'fixnum))
	  (copy (make-array n :element-type 'fixnum))
	  (num 0)
	  (cflip (the (function ((simple-array sb (*)))) (eval `(countfliplambda ,n))))
	  (copyfn (the (function ((simple-array sb (*)) (simple-array sb (*)))) (eval `(setlambda ,n)))))
      (declare (type (simple-array sb (*)) perm copy)
	       (type sb num))

      (loop for i from 0 to (- n 1) do (setf (aref perm i) i))
      
      (labels ((do-iter (ht)
		 (declare (type sb ht))
		 (if (= ht 1)
		     (progn
		       (funcall copyfn perm copy)
		       (let ((c (funcall cflip copy)))
			 (declare (type sb c))
			 (setf csum (sb (+ csum  (sb (if (evenp num) c (- c))))))
			 (when (> c fmax)
			   (setf fmax c)))
		       (incf num))
		     (loop for i of-type sb from 1 to ht do
			  (let ((m (- ht 1))) 
			    (do-iter m)
			    (let ((temp (aref perm 0)))
			      (loop for i from 1 to m do
				   (setf (aref perm (- i 1)) (aref perm i)))
			      (setf (aref perm m) temp)))))))

	(do-iter n)))
    (format t "~s~%Pfannkuchen(~s) = ~s~%" csum n fmax)))


(defun main ()  
  (let* ((args (cdr sb-ext:*posix-argv*))
         (n (parse-integer (car args))))
    (fannkuch n)))

 make, command-line, and program output logs

Tue, 25 Nov 2014 05:17:08 GMT

MAKE:
cp: ‘fannkuchredux.sbcl-3.sbcl’ and ‘./fannkuchredux.sbcl-3.sbcl’ are the same file
SBCL built with: /usr/local/bin/sbcl --userinit /dev/null --batch --eval '(load "fannkuchredux.sbcl-3.sbcl_compile")'
### START fannkuchredux.sbcl-3.sbcl_compile
(handler-bind ((sb-ext:defconstant-uneql      (lambda (c) (abort c))))      (load (compile-file "fannkuchredux.sbcl-3.sbcl" ))) (save-lisp-and-die "sbcl.core" :purify t)
### END fannkuchredux.sbcl-3.sbcl_compile

; compiling file "/home/dunham/benchmarksgame/bench/fannkuchredux/fannkuchredux.sbcl-3.sbcl" (written 23 JAN 2013 08:16:55 PM):
; compiling (DECLAIM (OPTIMIZE # ...))
; compiling (DEFMACRO SB ...)
; compiling (DEFTYPE SB ...)
; compiling (DEFMACRO SETLAMBDA ...)
; compiling (DEFMACRO COUNTFLIPLAMBDA ...)
; compiling (DEFUN FANNKUCH ...)
; compiling (DEFUN MAIN ...)

; /home/dunham/benchmarksgame_quadcore/fannkuchredux/tmp/fannkuchredux.sbcl-3.fasl written
; compilation finished in 0:00:00.056
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into sbcl.core:
writing 5680 bytes from the read-only space at 0x20000000
writing 3120 bytes from the static space at 0x20100000
writing 50298880 bytes from the dynamic space at 0x1000000000
done]
### START fannkuchredux.sbcl-3.sbcl_run
(main) (quit)
### END fannkuchredux.sbcl-3.sbcl_run

0.44s to complete and log all make actions

COMMAND LINE:
/usr/local/bin/sbcl  --noinform --core sbcl.core --userinit /dev/null --load fannkuchredux.sbcl-3.sbcl_run 12

PROGRAM OUTPUT:
3968050
Pfannkuchen(12) = 65

Revised BSD license

  Home   Conclusions   License   Play