Quickies

[categories] [index] [all (527)] [latest]

Python
  1. import cProfile, pstats, io
    from pstats import SortKey
    
    # ...
    
    pr = cProfile.Profile()
    pr.enable()
    
    f() # <- code to profile here
    
    pr.disable()
    s = io.StringIO()
    sortby = SortKey.CUMULATIVE
    ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
    ps.print_stats()
    print(s.getvalue())