Skip to content

Instantly share code, notes, and snippets.

@greggirwin
Created May 13, 2020 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greggirwin/a46d86d6c62dbd543749d1d3447f0f2d to your computer and use it in GitHub Desktop.
Save greggirwin/a46d86d6c62dbd543749d1d3447f0f2d to your computer and use it in GitHub Desktop.
Non-local timing markers
time-marks: object [
data: #()
;!! Watch for [set clear] system word usage in this object!
set: func [key] [
either key = /all [
print ["##ERROR time-marks/set reserves /all as an internal key."]
none
][
data/:key: now/precise
]
]
clear: func [key] [
either key = /all [system/words/clear data][remove/key data key]
]
since?: function [key] [
either key = /all [
res: copy data
foreach [key val] data [
res/:key: difference now/precise val
]
res
][
either data/:key [difference now/precise data/:key][
print ["##ERROR time-marks/since? was called for an unknown key:" key]
none
]
]
]
]
e.g.: :comment ; :do
e.g. [
time-marks/set 'a
wait 1
time-marks/set 'b
wait 2
time-marks/set 'c
time-marks/since? #xxx
print time-marks/since? 'a
print time-marks/since? 'b
print time-marks/since? 'c
print mold time-marks/since? /all
print time-marks/clear 'b
time-marks/since? 'b
print time-marks/clear /all
print mold time-marks/since? /all
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment