Last active
December 8, 2023 22:06
-
-
Save max-power/30abf44b3584f846d09d873c2ebb25d5 to your computer and use it in GitHub Desktop.
Simple timing functions. Include it or use as standalone module
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
module Timer | |
module_function | |
def time unit = :microsecond | |
Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) | |
end | |
def time_it start = time | |
yield | |
time_diff start | |
end | |
def time_diff start, stop = time | |
((stop - start) / 1000.0).round | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment