Package: pstatsdecorator
Decorator for pstats$pipinstallpstatsdecoratorfrompstatsdecoratorimportpstats_check# Valid parameters for sortby:# 'calls'# 'cumulative'# 'cumtime'# 'file'# 'filename'# 'module'# 'ncalls'# 'pcalls'# 'line'# 'name'# 'nfl'# 'stdname'# 'time'# 'tottime'# if return_stats is enabled, the function will always return a tuple.# The last element in the tuple is the pstats data@pstats_check(print_stats=False,return_stats=True,sortby="filename")deftestest1():print(isinstance("aaaaaaaaaa",str))print("aaaaaaaaaaaaaaaaa")x=20+1returnx@pstats_check(print_stats=True,return_stats=False,sortby="line")deftestest2():importrere.findall("b","bbbbbbbbbbbbbbbbbbbbb")print("bbbbbbbbbbbbbbbbbbbbb")print("bbbbbbbbbbbbbbbbbbbbb")x=200+1returnx@pstats_check(print_stats=True,return_stats=False,sortby="cumulative")deftestest3():print("ccccccccccccccccccccccccc")x=2000+1returnxprint("k ----------------------------->")k=testest1()print(f"xxxxxxxxxxxxxxx\n{k=}")print("<----------------------------- k")print("k1 ----------------------------->")k1=testest2()print(f"xxxxxxxxxxxxxxx\n{k1=}")print("<----------------------------- k1")print("k2 ----------------------------->")k2=testest3()print(f"xxxxxxxxxxxxxxx\n{k2=}")print("<----------------------------- k2")Output:k----------------------------->Trueaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxk=(21,"         7 function calls in 0.000 seconds\n\nOrdered by: file name\n\nncalls  tottime  percall  cumtime  percall filename:lineno(function)\n1    0.000    0.000    0.000    0.000 <ipython-input-2-be27ae79f5ac>:21(testest1)\n1    0.000    0.000    0.000    0.000 C:\\Users\\Gamer\\anaconda3\\envs\\dfdir\\lib\\cProfile.py:106(runcall)\n1    0.000    0.000    0.000    0.000 {method 'enable' of '_lsprof.Profiler' objects}\n1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}\n1    0.000    0.000    0.000    0.000 {built-in method builtins.isinstance}\n2    0.000    0.000    0.000    0.000 {built-in method builtins.print}\n\n\n")<-----------------------------kk1----------------------------->bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb85functioncalls(84primitivecalls)in0.000secondsOrderedby:linenumberncallstottimepercallcumtimepercallfilename:lineno(function)10.0000.0000.0000.000{method'enable'of'_lsprof.Profiler'objects}10.0000.0000.0000.000{method'disable'of'_lsprof.Profiler'objects}10.0000.0000.0000.000{method'findall'of're.Pattern'objects}10.0000.0000.0000.000{built-inmethod_sre.compile}10.0000.0000.0000.000{method'items'of'dict'objects}130.0000.0000.0000.000{method'append'of'list'objects}20.0000.0000.0000.000{method'extend'of'list'objects}10.0000.0000.0000.000{built-inmethodbuiltins.__import__}80.0000.0000.0000.000{built-inmethodbuiltins.isinstance}13/120.0000.0000.0000.000{built-inmethodbuiltins.len}30.0000.0000.0000.000{built-inmethodbuiltins.min}10.0000.0000.0000.000{built-inmethodbuiltins.ord}20.0000.0000.0000.000{built-inmethodbuiltins.print}10.0000.0000.0000.000C:\ProgramFiles\JetBrains\PyCharmCommunityEdition2020.3\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py:16(do_import)10.0000.0000.0000.000<ipython-input-2-be27ae79f5ac>:36(testest2)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:76(__init__)20.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:82(groups)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:87(_compile)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\cProfile.py:106(runcall)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:112(__init__)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:161(__len__)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:165(__getitem__)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:173(append)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:175(getwidth)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:225(__init__)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\re.py:233(findall)20.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:234(__next)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:250(match)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:255(get)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:287(tell)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\re.py:289(_compile)20.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\enum.py:358(__call__)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:436(_parse_sub)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:456(_generate_overlap_table)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:477(_get_iscased)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:485(_get_literal_prefix)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:494(_parse)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:560(_compile_info)20.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:619(isstring)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:622(_code)20.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\enum.py:670(__new__)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_compile.py:783(compile)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:928(fix_flags)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\sre_parse.py:944(parse)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\enum.py:977(__and__)xxxxxxxxxxxxxxxk1=201<-----------------------------k1k2----------------------------->ccccccccccccccccccccccccc5functioncallsin0.000secondsOrderedby:cumulativetimencallstottimepercallcumtimepercallfilename:lineno(function)10.0000.0000.0000.000C:\Users\Gamer\anaconda3\envs\dfdir\lib\cProfile.py:106(runcall)10.0000.0000.0000.000<ipython-input-2-be27ae79f5ac>:54(testest3)10.0000.0000.0000.000{built-inmethodbuiltins.print}10.0000.0000.0000.000{method'enable'of'_lsprof.Profiler'objects}10.0000.0000.0000.000{method'disable'of'_lsprof.Profiler'objects}xxxxxxxxxxxxxxxk2=2001<-----------------------------k2