initial import
benchmark.lisp
Mon May 25 16:59:32 CEST 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
* initial import
--- old-benchmark/benchmark.lisp 1970-01-01 01:00:00.000000000 +0100
+++ new-benchmark/benchmark.lisp 2014-10-30 07:07:28.000000000 +0100
@@ -0,0 +1,53 @@
+(in-package :cl-smoke.benchmark)
+
+(defun timing (function &rest arguments)
+ (let ((timings))
+ (apply #'sb-ext:call-with-timing
+ #'(lambda (&rest args)
+ (setf timings args))
+ function
+ arguments)
+ (list :processor-cycles (getf timings :processor-cycles))))
+
+(defun print-header (stream data)
+ (dolist (d (alexandria:plist-alist (first data)))
+ (format stream "~A " (first d)))
+ (format stream "~%"))
+
+(defun write-R-table (data file)
+ (with-open-file (out file :direction :output)
+ (print-header out data)
+ (dolist (d data)
+ (dolist (e (alexandria:plist-alist d))
+ (format out "~S~T" (rest e)))
+ (format out "~%"))))
+
+
+(defun benchmark (function &rest args)
+ (let ((data))
+ (dotimes (n 20 data)
+ (sb-ext:gc :full t)
+ (push (apply #'timing function args)
+ data))))
+
+(defun run-compare (name function cxx-function iterations)
+ (let ((data (benchmark function iterations))
+ (cxx-data (benchmark cxx-function iterations))
+ (file (make-pathname :defaults name
+ :type "dat")))
+ (write-R-table data file)
+ (write-R-table cxx-data
+ (make-pathname :defaults file
+ :name (concatenate 'string
+ "cxx-"
+ (pathname-name file))))))
+
+(defun run ()
+ (run-compare "overload" #'overload #'cl-smoke-benchmark-overload 1000)
+ (run-compare "inline-call" #'inline-call
+ #'cl-smoke-benchmark-byte-array-size 1000)
+ (run-compare "simple-call" #'simple-call
+ #'cl-smoke-benchmark-simple-call 1000)
+ (with-benchmark-cxx-construct (1000)
+ (run-compare "construct" #'construct
+ #'cl-smoke-benchmark-construct 1000)))