Skip to content

Instantly share code, notes, and snippets.

@gpiffault
Last active November 18, 2021 10:47
Show Gist options
  • Save gpiffault/38893b27fa5158f25c2eb8edf1bd068b to your computer and use it in GitHub Desktop.
Save gpiffault/38893b27fa5158f25c2eb8edf1bd068b to your computer and use it in GitHub Desktop.
Handy print with timing
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