module pycode.profiling

Short summary

module pyquickhelper.pycode.profiling

Profiling helpers

source on GitHub

Functions

function

truncated documentation

_process_pstats

Converts class Stats into something readable for …

profile

Profiles the execution of a function.

Documentation

Profiling helpers

source on GitHub

pyquickhelper.pycode.profiling._process_pstats(ps, clean_text)[source][source]

Converts class Stats into something readable for a dataframe.

source on GitHub

pyquickhelper.pycode.profiling.profile(fct, sort='cumulative', rootrem=None, as_df=False, pyinst_format=None, **kwargs)[source][source]

Profiles the execution of a function.

Parameters
  • fct – function to profile

  • sort – see sort_stats

  • rootrem – root to remove in filenames

  • as_df – return the results as a dataframe and not text

  • pyinst_format – format for pyinstrument, if not empty, the function uses this module or raises an exception if not installed, the options are text, textu (text with colors), json, html

  • kwargs – additional parameters used to create the profiler

Returns

raw results, statistics text dump (or dataframe is as_df is True)

import matplotlib.pyplot as plt
from pyquickhelper.pycode.profiling import profile
from pyquickhelper.texthelper import compare_module_version

def fctm():
    return compare_module_version('0.20.4', '0.22.dev0')

pr, df = profile(lambda: [fctm() for i in range(0, 1000)], as_df=True)
ax = df[['namefct', 'cum_tall']].head(n=15).set_index(
    'namefct').plot(kind='bar', figsize=(8, 3), rot=30)
ax.set_title("example of a graph")
for la in ax.get_xticklabels():
    la.set_horizontalalignment('right');
plt.show()

(png, hires.png, pdf)

../../_images/profiling-1.png

source on GitHub