Last active
October 11, 2019 07:21
-
-
Save tvst/ad39fc29d69a933141c7a4564287cbf2 to your computer and use it in GitHub Desktop.
An easy-to-use poor-man's profiler using Streamlit. See: https://discuss.streamlit.io/t/how-to-tell-which-variables-are-being-recomputed/359
This file contains 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 streamlit as st | |
import time | |
class TimeIt(object): | |
"""Simple timer for profiling Streamlit apps. | |
Usage | |
----- | |
>>> t = TimeIt() | |
>>> do_stuff() | |
>>> t.tick('did stuff') | |
>>> do_more_stuff() | |
>>> t.tick('did more stuff') | |
""" | |
def __init__(self): | |
self.prev_time = time.time() | |
def tick(self, msg=''): | |
new_time = time.time() | |
delta = new_time - self.prev_time | |
st.write('_%s [Ellapsed time: %0.3fs]_' % (msg, delta)) | |
self.prev_time = new_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment