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
5000.390.39260906  3% 0% 5% 100%
3,0004.874.8817,652906  1% 0% 1% 100%
5,50015.8815.8920,068906  0% 1% 1% 100%

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

Read spectral-norm benchmark to see what this program should do.


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

 spectral-norm Lisp SBCL #2 program source code

;;    The Computer Language Benchmarks Game
;;    Adapted from the C (gcc) code by Sebastien Loisel
;;    Contributed by Christopher Neufeld
;;    Modified by Juho Snellman 2005-10-26
;;      * Use SIMPLE-ARRAY instead of ARRAY in declarations
;;      * Use TRUNCATE instead of / for fixnum division
;;      * Rearrange EVAL-A to make it more readable and a bit faster
;;    Modified by Andy Hefner 2008-09-18
;;      * Eliminate array consing
;;      * Clean up type declarations in eval-A
;;      * Distribute work across multiple cores on SBCL
;;    Modified by Witali Kusnezow 2008-12-02
;;      * use right shift instead of truncate for division in eval-A
;;      * redefine eval-A as a macro
;;    Modified by Lorenzo Bolla 2010-12-06
;;      * added declaim at top of file

;; This is our most expensive function.  Optimized with the knowledge
;; that 'n' will never be "huge".  This will break if 'n' exceeds
;; approximately half of the square root of the largest fixnum
;; supported by the implementation.  On 32-bit sbcl,
;; 'most-positive-fixnum' is 536870911, and we can support values of
;; 'n' above 11000.

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

(defmacro eval-A (i j)
  `(let* ((n (+ ,i ,j))
          (n+1 (1+ n)))
     (declare (type (integer 0 22000) n n+1))
     (/ (float (+ (ash (* n n+1) -1) ,i 1) 0d0))))

(defun eval-At-times-u (u n Au start end)
  (declare (type fixnum n start end)
           (type (simple-array double-float) u Au))
  (loop for i from start below end do
        (setf (aref Au i)
              (loop for j below n
                    summing (* (aref u j) (eval-A j i))
                    of-type double-float))))

(defun eval-A-times-u (u n Au start end)
  (declare (type fixnum n start end)
           (type (simple-array double-float) u Au))
  (loop for i from start below end do
        (setf (aref Au i)
              (loop for j below n
                    summing (* (aref u j) (eval-A i j))
                    of-type double-float))))

(defun execute-parallel (start end function)
  (declare (optimize (speed 0)))
  (let* ((num-threads 4))
    (loop with step = (truncate (- end start) num-threads)
          for index from start below end by step
          collecting (let ((start index)
                           (end (min end (+ index step))))
                        (lambda () (funcall function start end))))
          into threads
          finally (mapcar #'sb-thread:join-thread threads))))

(defun execute-parallel (start end function )
  (funcall function start end))

(defun eval-AtA-times-u (u AtAu v n start end)
  (execute-parallel start end
    (lambda (start end)
      (eval-A-times-u u n v start end)))
  (execute-parallel start end
    (lambda (start end)
      (eval-At-times-u v n AtAu start end))))

(defun main (&optional n-supplied)
  (let ((n (or n-supplied
               (parse-integer (or (car (last #+sbcl sb-ext:*posix-argv*
                                             #+clisp ext:*args*
                                             #+cmu extensions:*command-line-strings*
                                             #+gcl  si::*command-args*))
    (declare (type fixnum n))
    (or (typep (* (- (* 2 n) 1) (- (* 2 n) 2)) 'fixnum)
        (error "The supplied value of 'n' breaks the optimizations in EVAL-A"))
    (let ((u (make-array n :element-type 'double-float :initial-element 1.0d0))
          (v (make-array n :element-type 'double-float))
          (tmp (make-array n :element-type 'double-float)))
      (declare (type (simple-array double-float) U V))
      (dotimes (i 10)
        (eval-AtA-times-u u v tmp n 0 n)
        (eval-AtA-times-u v u tmp n 0 n))
      (let ((vBv 0.0d0)
            (vv 0.0d0))
        (dotimes (i n)
          (incf vBv (* (aref u i) (aref v i)))
          (incf vv (* (aref v i) (aref v i))))
        (format t "~11,9F~%" (sqrt (the (double-float 0d0) (/ vBv vv))))))))

 make, command-line, and program output logs

Thu, 02 Apr 2015 03:27:32 GMT

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

; compiling file "/home/dunham/benchmarksgame/bench/spectralnorm/spectralnorm.sbcl-2.sbcl" (written 24 JAN 2013 02:01:16 PM):
; compiling (DECLAIM (OPTIMIZE # ...))
; compiling (DEFMACRO EVAL-A ...)
; compiling (DEFUN EVAL-AT-TIMES-U ...)
; compiling (DEFUN EVAL-A-TIMES-U ...)
; compiling (DEFUN EXECUTE-PARALLEL ...)
; compiling (DEFUN EVAL-ATA-TIMES-U ...)
; compiling (DEFUN MAIN ...)
; file: /home/dunham/benchmarksgame/bench/spectralnorm/spectralnorm.sbcl-2.sbcl
;     (* (- (* 2 N) 1) (- (* 2 N) 2))
; note: forced to do GENERIC-* (cost 30)
;       unable to do inline fixnum arithmetic (cost 4) because:
;       The first argument is a (INTEGER -1073741825 1073741821), not a FIXNUM.
;       The second argument is a (INTEGER -1073741826 1073741820), not a FIXNUM.
;       The result is a (VALUES
;                        (INTEGER -1152921503533105146 1152921507828072450)
;                        &OPTIONAL), not a (VALUES FIXNUM &REST T).
;       unable to do inline (signed-byte 32) arithmetic (cost 5) because:
;       The result is a (VALUES
;                        (INTEGER -1152921503533105146 1152921507828072450)
;                        &OPTIONAL), not a (VALUES (SIGNED-BYTE 32) &REST T).
;       etc.
; note: doing signed word to integer coercion (cost 20), for:
;       the first argument of GENERIC-*
; note: doing signed word to integer coercion (cost 20), for:
;       the second argument of GENERIC-*

;     (FORMAT T "~11,9F~%" (SQRT (THE (DOUBLE-FLOAT 0.0d0) (/ VBV VV))))
; ==>
;                            #:FVAR882 #:FVAR883 NIL)
; note: doing float to pointer coercion (cost 13)
; compilation unit finished
;   printed 4 notes

; /home/dunham/benchmarksgame_onecore/spectralnorm/tmp/spectralnorm.sbcl-2.fasl written
; compilation finished in 0:00:00.041
[undoing binding stack and other enclosing state... done]
[saving current Lisp image into sbcl.core:
writing 3496 bytes from the read-only space at 0x1000000
writing 2272 bytes from the static space at 0x1100000
writing 30994432 bytes from the dynamic space at 0x9000000
### START spectralnorm.sbcl-2.sbcl_run
(main) (quit)
### END spectralnorm.sbcl-2.sbcl_run

0.72s to complete and log all make actions

/usr/local/bin/sbcl   --noinform --core sbcl.core --userinit /dev/null --load spectralnorm.sbcl-2.sbcl_run 5500


Revised BSD license

  Home   Conclusions   License   Play