Skip to content

Instantly share code, notes, and snippets.

@stassats
Created November 16, 2015 21:09
Show Gist options
  • Save stassats/33bd12b2f5a4b8dcab6a to your computer and use it in GitHub Desktop.
Save stassats/33bd12b2f5a4b8dcab6a to your computer and use it in GitHub Desktop.
(defparameter *funs* '(FLOOR FFLOOR CEILING FCEILING TRUNCATE FTRUNCATE ROUND FROUND))
(defparameter *types*
'((double-float 10d0)
(single-float 30f0)
(integer 31)
(ratio 1/2 3/2 1/255)))
(defun make-test-case (fun number-type divisor-type)
(let ((inputs (cdr (assoc number-type *types*)))
(divisors (cdr (assoc divisor-type *types*))))
(cons (loop for divisor in divisors
collect
(compile nil
`(sb-int:named-lambda (,fun ,divisor)
(x)
(declare (type ,number-type x))
(,fun x ,divisor))))
inputs)))
(defparameter *tests*
(loop for fun in *funs*
nconc (loop for (number-type) in *types*
nconc (loop for (divisor-type) in *types*
collect (make-test-case fun number-type divisor-type)))))
(defun run-tests (n)
(write-line "FUNCTION|X|Y|TIME|CONS")
(loop for (funs . inputs) in *tests*
do (loop for fun in funs
do (length inputs)
(loop for input in inputs
do
(sb-ext:gc :full t)
(sb-ext:call-with-timing
(lambda (&key real-time-ms bytes-consed
&allow-other-keys)
(format t "~a|~a|~a|~a|~a~%"
(car (sb-kernel:%fun-name fun))
input
(cadr (sb-kernel:%fun-name fun))
(/ real-time-ms 1000.0)
bytes-consed))
(lambda ()
(loop repeat n
do (funcall (truly-the function fun)
input))))))))
d <- read.csv("/tmp/bench-before.csv", sep="|")
library(ggplot2)
png("/tmp/plot-before.png", width=2048, height=2048)
print(ggplot(d, aes(x=FUNCTION, y=TIME)) + geom_bar(stat="identity")
+ facet_grid(X ~ Y)+ scale_y_continuous(limits=c(0,0.1))
+ labs(title = "Before", y = "Time, seconds")
+ theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)))
dev.off()
d <- read.csv("/tmp/bench-after.csv", sep="|")
library(ggplot2)
png("/tmp/plot-after.png", width=2048, height=2048)
print(ggplot(d, aes(x=FUNCTION, y=TIME)) + geom_bar(stat="identity")
+ facet_grid(X ~ Y)+ scale_y_continuous(limits=c(0,0.1))
+ labs(title = "After", y = "Time, seconds")
+ theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5)))
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment