I am experiencing 3 different performance results consistently with the same code, depending on how I load it. Here is the test code:
(in-package #:cl-user)
(defpackage #:origin2
(:use #:static-dispatch-cl))
(in-package #:origin2)
(defstruct (aggregate
(:predicate nil)
(:copier nil))
(storage (make-array 0 :element-type 'single-float :initial-element 0.0) :type (simple-array single-float (*))))
(defgeneric ref (sequence index)
(:method ((sequence aggregate) index)
(elt (aggregate-storage sequence) index)))
(defun test ()
(declare (optimize (speed 3)))
(let ((a (make-aggregate :storage (make-array 3 :element-type 'single-float :initial-contents '(1.0 2.0 3.0)))))
(declare (type aggregate a))
(dotimes (i (expt 10 9))
(ref a 2))))
Clearing FASL's, loading this code into my image on SBCL 2.1.7, and issuing:
(progn
(sb-ext:gc :full t)
(time (test)))
I get these results consistently:
Evaluation took:
7.146 seconds of real time
7.130177 seconds of total run time (7.130177 user, 0.000000 system)
99.78% CPU
20 lambdas converted
14,232,702,075 processor cycles
1,080,336 bytes consed
If I now re-compile the #'test function in the same image, and re-run the test I consistently get:
Evaluation took:
0.350 seconds of real time
0.351234 seconds of total run time (0.351196 user, 0.000038 system)
100.29% CPU
701,597,093 processor cycles
0 bytes consed
If I wrap the defgeneric in (eval-when (:compile-toplevel :load-toplevel :execute) ...), clear FASL's, loading the code, and re-run the test, I consistently get:
Evaluation took:
0.583 seconds of real time
0.579642 seconds of total run time (0.579642 user, 0.000000 system)
99.49% CPU
1,157,429,524 processor cycles
0 bytes consed
I get no warnings from static-dispatch in all 3 cases, and everything compiles cleanly. I would like to know why these differences are occurring, and how I would get the results of the second test above from a clean image (instead of manually recompiling the function after loading). Thank you for your help.
I am experiencing 3 different performance results consistently with the same code, depending on how I load it. Here is the test code:
Clearing FASL's, loading this code into my image on SBCL 2.1.7, and issuing:
I get these results consistently:
If I now re-compile the
#'testfunction in the same image, and re-run the test I consistently get:If I wrap the
defgenericin(eval-when (:compile-toplevel :load-toplevel :execute) ...), clear FASL's, loading the code, and re-run the test, I consistently get:I get no warnings from static-dispatch in all 3 cases, and everything compiles cleanly. I would like to know why these differences are occurring, and how I would get the results of the second test above from a clean image (instead of manually recompiling the function after loading). Thank you for your help.