Login
7 branches 0 tags
Ben (Win10) Removed clang64 due to issues with the day1 AoC Test 5a555ae 4 years ago 265 Commits
nujel / stdlib / time.nuj
; Time related λs

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

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

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

[defun 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]]]
]