(defun square (x) (* x x)) (defstruct point (x 0.0 :type float) (y 0.0 :type float) (z 0.0 :type float)) (defun init-point (n point) (let* ((x (coerce n 'float)) (y (sin x))) (setf (point-x point) y) (setf (point-y point) (* 3 (cos x))) (setf (point-z point) (/ (* y y) 2)))) (defun make-points (len) (let ((points (make-array len :element-type 'point))) (dotimes (i len) (let ((point (make-point))) (init-point i point) (setf (elt points i) point))) points)) (defun point-norm (point) (sqrt (+ (square (point-x point)) (square (point-y point)) (square (point-z point))))) (defun normalize-point (point) (let ((x (point-norm point))) (setf (point-x point) (/ (point-x point) x)) (setf (point-y point) (/ (point-y point) x)) (setf (point-z point) (/ (point-z point) x)))) (defun max-point (point-a point-b) (setf (point-x point-a) (max (point-x point-a) (point-x point-b))) (setf (point-y point-a) (max (point-y point-a) (point-y point-b))) (setf (point-z point-a) (max (point-z point-a) (point-z point-b))) point-a) (defun print-point (point) (format t "~a, ~a, ~a~%" (point-x point) (point-y point) (point-z point))) (defun bench () (let ((points (make-points 500000))) (map nil #'normalize-point points) (print-point (reduce #'max-point points :initial-value (make-point :x 0.0 :y 0.0 :z 0.0))))) (defun stime (x) (let* ((a (get-internal-real-time)) (b (funcall x)) (c (get-internal-real-time))) (format t "Time: ~a~%" (- c a)) b)) (dotimes (i 8) (format t "Run #~a~%" i) (stime #'bench))