https://github.com/annotation/text-fabric
Raw File
Tip revision: ae8c1106e0d61c84aa0b70837767a8e81b878a1f authored by Dirk Roorda on 02 February 2022, 12:57:55 UTC
fixed bug in writedatatf
Tip revision: ae8c110
utils.py
import io
import cProfile
import pstats
from pstats import SortKey


def prof_x(code, g, l):
  cProfile.runctx(code, g, l, sort=SortKey.CUMULATIVE)


def prof(func, g, l, *args, **kwargs):
  globals().update(g)
  locals().update(l)
  pr = cProfile.Profile()
  pr.enable()
  results = func(*args, **kwargs)
  pr.disable()
  s = io.StringIO()
  sortby = SortKey.CUMULATIVE
  ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
  ps.print_stats()
  print(s.getvalue())
  return results
back to top