MCPcopy Index your code
hub / github.com/clips/pattern / profile

Function profile

pattern/metrics.py:73–93  ·  view source on GitHub ↗

Returns the performance statistics (as a string) of the given Python function.

(function, *args, **kwargs)

Source from the content-addressed store, hash-verified

71 return time() - t
72
73def profile(function, *args, **kwargs):
74 """ Returns the performance statistics (as a string) of the given Python function.
75 """
76 def run():
77 function(*args, **kwargs)
78 try:
79 import cProfile as profile
80 except:
81 import profile
82 import pstats
83 import os
84 import sys; sys.modules["__main__"].__profile_run__ = run
85 id = function.__name__ + "()"
86 profile.run("__profile_run__()", id)
87 p = pstats.Stats(id)
88 p.stream = open(id, "w")
89 p.sort_stats("time").print_stats(20)
90 p.stream.close()
91 s = open(id).read()
92 os.remove(id)
93 return s
94
95#### PRECISION & RECALL ############################################################################
96

Callers

nothing calls this directly

Calls 4

runMethod · 0.45
closeMethod · 0.45
readMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…