Created
          May 13, 2020 04:00 
        
      - 
      
 - 
        
Save greggirwin/a46d86d6c62dbd543749d1d3447f0f2d to your computer and use it in GitHub Desktop.  
    Non-local timing markers
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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