initial import
Annotate for file benchmark.lisp
2009-05-25 tobias 1 (in-package :cl-smoke.benchmark)
14:59:32 ' 2
' 3 (defun timing (function &rest arguments)
' 4 (let ((timings))
' 5 (apply #'sb-ext:call-with-timing
' 6 #'(lambda (&rest args)
' 7 (setf timings args))
' 8 function
' 9 arguments)
' 10 (list :processor-cycles (getf timings :processor-cycles))))
' 11
' 12 (defun print-header (stream data)
' 13 (dolist (d (alexandria:plist-alist (first data)))
' 14 (format stream "~A " (first d)))
' 15 (format stream "~%"))
' 16
' 17 (defun write-R-table (data file)
' 18 (with-open-file (out file :direction :output)
' 19 (print-header out data)
' 20 (dolist (d data)
' 21 (dolist (e (alexandria:plist-alist d))
' 22 (format out "~S~T" (rest e)))
' 23 (format out "~%"))))
' 24
' 25
' 26 (defun benchmark (function &rest args)
' 27 (let ((data))
' 28 (dotimes (n 20 data)
' 29 (sb-ext:gc :full t)
' 30 (push (apply #'timing function args)
' 31 data))))
' 32
' 33 (defun run-compare (name function cxx-function iterations)
' 34 (let ((data (benchmark function iterations))
' 35 (cxx-data (benchmark cxx-function iterations))
' 36 (file (make-pathname :defaults name
' 37 :type "dat")))
' 38 (write-R-table data file)
' 39 (write-R-table cxx-data
' 40 (make-pathname :defaults file
' 41 :name (concatenate 'string
' 42 "cxx-"
' 43 (pathname-name file))))))
' 44
' 45 (defun run ()
' 46 (run-compare "overload" #'overload #'cl-smoke-benchmark-overload 1000)
' 47 (run-compare "inline-call" #'inline-call
' 48 #'cl-smoke-benchmark-byte-array-size 1000)
' 49 (run-compare "simple-call" #'simple-call
' 50 #'cl-smoke-benchmark-simple-call 1000)
' 51 (with-benchmark-cxx-construct (1000)
' 52 (run-compare "construct" #'construct
' 53 #'cl-smoke-benchmark-construct 1000)))