Login
7 branches 0 tags
Ben (X13/Arch) Fixed Array OOM 6b9fa21 3 years ago 676 Commits
nujel / stdlib / datetime / time.nuj
;; Nujel - Copyright (C) 2020-2021 - Benjamin Vincent Schulenburg
;; This project uses the MIT license, a copy should be included under /LICENSE
;;
;; Time related λs

[defn time/seconds [timestamp]
      "Return the seconds part of TIMESTAMP, defaults to current time"
      [% [default timestamp [time]] 60]]

[defn time/minutes [timestamp]
      "Return the minutes part of TIMESTAMP, defaults to current time"
      [% [/ [default timestamp [time]] 60] 60]]

[defn time/hours [timestamp]
      "Return the hours part of TIMESTAMP, defaults to current time"
      [% [/ [default timestamp [time]] 3600] 24]]

[defn profile-form [raw]
      [def start-time [time/milliseconds]]
      [def val [eval raw]]
      [def end-time [time/milliseconds]]
      [display [cat "Evaluating " [ansi-yellow [str/write raw]] " to " [ansi-green [str/write val]] " took " [ansi-red [cat [- end-time start-time] "ms"] "\n"]]]]

[defmacro profile body
          "Measure and display how much time and ressources it takes for BODY to be evaluated"
          `[profile-form '~[if [last? body]
                               [car body]
                               [cons 'do body]]]]