Last active
November 18, 2021 10:47
-
-
Save gpiffault/38893b27fa5158f25c2eb8edf1bd068b to your computer and use it in GitHub Desktop.
Handy print with timing
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
import time | |
class ChronoPrint: | |
"""Usage: | |
cp = ChronoPrint() | |
foo() | |
cp("foo") # prints: 1.21 foo | |
bar() | |
cp("bar") # prints: 0.72 bar | |
""" | |
def __init__(self): | |
self.last_lap = time.time() | |
def __call__(self, *msg, **kwargs): | |
now = time.time() | |
print(round(now - self.last_lap, 2), *msg, **kwargs) | |
self.last_lap = now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment