From bc3d7629cbbb8aee1b5ca78bd59f4f394b71a166 Mon Sep 17 00:00:00 2001 From: Izaak Walton Date: Thu, 10 Oct 2024 21:28:47 -0700 Subject: [PATCH] Remove conditionals from profiling --- library/system.lisp | 51 +++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/library/system.lisp b/library/system.lisp index d9c23650..81386e23 100644 --- a/library/system.lisp +++ b/library/system.lisp @@ -10,7 +10,7 @@ (:export #:get-real-time #:get-run-time - #+sbcl #:get-bytes-consed + #:monotonic-bytes-consed #:Profile #:capture-profile) (:export @@ -76,55 +76,56 @@ While the result will always contain microseconds, some implementations may retu (declare get-run-time (Unit -> UFix)) (define (get-run-time) - "Gets the run-time." + "Gets the run-time in microseconds." (lisp UFix () (cl:get-internal-run-time))) (declare get-real-time (Unit -> UFix)) (define (get-real-time) - "Gets the real-time." + "Gets the real-time in microseconds." (lisp UFix () (cl:get-internal-real-time))) - #+sbcl - (declare get-bytes-consed (Unit -> UFix)) - #+sbcl - (define (get-bytes-consed) - "Gets the number of bytes consed (only implemented for SBCL" - (lisp UFix () - (sb-ext:get-bytes-consed))) + (declare monotonic-bytes-consed (Unit -> (Optional Integer))) + (define (monotonic-bytes-consed) + "Return the number of bytes consed since some unspecified point in time. +The difference between two successive calls to this function represents the number of bytes consed in that period of time." + #+sbcl + (Some (lisp Integer () + (sb-ext:get-bytes-consed))) + #-sbcl + None) (define-struct (Profile :a) - "A profile of a run function." + "A profile of a function, containing space and timing information.." (output - "The output of the function" :a) + "The output of the function." :a) (run-time - "The run time of the run" UFix) + "The run time of the run in microseconds." UFix) (real-time - "The real time of the run" UFix) - #+sbcl + "The real time of the run in microseconds" UFix) (bytes-consed - "The number of bytes consed during the run." UFix)) + "The number of bytes consed during the run." (Optional Integer))) - (declare capture-profile ((Unit -> :a) -> (Profile :a))) - (define (capture-profile f) - "Runs a function, recording profile information and returning a Profile object." + (declare spacetime ((Unit -> :a) -> (Profile :a))) + (define (spacetime f) + "Runs a function, recording space and timing information and returning a Profile object." (gc) - (let (#+sbcl - (start-bytes-consed (get-bytes-consed)) + (let ((start-bytes-consed (monotonic-bytes-consed)) (start-run-time (get-run-time)) (start-real-time (get-real-time)) (value (f)) - #+sbcl - (end-bytes-consed (get-bytes-consed)) + (end-bytes-consed (monotonic-bytes-consed)) (end-run-time (get-run-time)) (end-real-time (get-real-time))) (Profile value (- end-run-time start-run-time) (- end-real-time start-real-time) - #+sbcl - (- end-bytes-consed start-bytes-consed))))) + (match (Tuple end-bytes-consed start-bytes-consed) + ((Tuple (Some a) (Some b)) + (Some (- a b))) + (_ None)))))) ;;; ;;; Gathering System information