Skip to content

Instantly share code, notes, and snippets.

@tvst
Last active October 11, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvst/ad39fc29d69a933141c7a4564287cbf2 to your computer and use it in GitHub Desktop.
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
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