Last active
January 22, 2020 17:40
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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