Skip to content

Instantly share code, notes, and snippets.

@marcoheisig
Last active January 22, 2020 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoheisig/945319f2f982336ecb1e3a43178ff3fb to your computer and use it in GitHub Desktop.
Save marcoheisig/945319f2f982336ecb1e3a43178ff3fb to your computer and use it in GitHub Desktop.
What ist the cost of having one (correctly predicted) branch at the beginning of a function?
(in-package :cl-user)
(defmacro debug-defun (name lambda-list &body body)
(multiple-value-bind (forms decls doc)
(alexandria:parse-body body :documentation t)
`(progn
(declaim (notinline ,name))
(defun ,name (.debug-flag. ,@lambda-list)
,@(when doc (list doc))
,@decls
(if .debug-flag.
(locally (declare (optimize (debug 3) (speed 0) (safety 3)))
,@forms)
(locally (declare (optimize (debug 0)))
,@forms))))))
(debug-defun foo (x y)
(declare (type (integer 0 100) x y))
(+ x y))
(declaim (notinline bar))
(defun bar (x y)
(declare (type (integer 0 100) x y))
(+ x y))
(defun foobar-bench ()
(time (loop repeat (expt 10 9) do (foo nil 2 3)))
(time (loop repeat (expt 10 9) do (bar 2 3))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment