a1bc13ae51e7

Improve `timing` driver

Don't calculate `since` unless we actually need it.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 22 Aug 2016 19:51:05 +0000
parents e21b181efc55
children 5b5e1b9adbbd
branches/tags (none)
files losh.lisp

Changes

--- a/losh.lisp	Mon Aug 22 19:43:24 2016 +0000
+++ b/losh.lisp	Mon Aug 22 19:51:05 2016 +0000
@@ -615,17 +615,17 @@
   (let ((timing-function (ecase time-type
                            ((real-time) #'get-internal-real-time)
                            ((run-time) #'get-internal-run-time)))
-        (since (or since-var (gensym))))
+        (since (or since-var (when (null per-var)
+                               iterate::*result-var*))))
     (with-gensyms (start-time current-time previous-time)
       `(progn
         (with ,start-time = (funcall ,timing-function))
         (for ,current-time = (funcall ,timing-function))
         (for ,previous-time :previous ,current-time :initially ,start-time)
-        (for ,since = (- ,current-time ,start-time))
+        ,(when since
+           `(for ,since = (- ,current-time ,start-time)))
         ,(when per-var
-           `(for ,per-var = (- ,current-time ,previous-time)))
-        ,(when (and (null since-var) (null per-var))
-           `(finally (return ,since)))))))
+           `(for ,per-var = (- ,current-time ,previous-time)))))))
 
 
 (defmacro-driver (FOR var IN-LISTS lists)