本文整理汇总了Python中line_profiler.LineProfiler.add_function方法的典型用法代码示例。如果您正苦于以下问题:Python LineProfiler.add_function方法的具体用法?Python LineProfiler.add_function怎么用?Python LineProfiler.add_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类line_profiler.LineProfiler
的用法示例。
在下文中一共展示了LineProfiler.add_function方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: benchmark
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def benchmark(cls, func, *args):
from line_profiler import LineProfiler
prf = LineProfiler()
prf.add_function(func)
ret = prf.runcall(func, *args)
prf.print_stats()
return ret
示例2: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def profiled_func(*args, **kwargs):
try:
lp = LineProfiler()
lp.add_function(f)
lp.enable_by_count()
return f(*args, **kwargs)
finally:
lp.print_stats()
示例3: DataReader_bin_test2
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def DataReader_bin_test2(self):
self.select_file(num=1)
prf = LineProfiler()
prf.add_function(self.read_bin_file_to_tx2)
prf.runcall(self.read_bin_file_to_tx2, start=3 * 10**7, datapoints=10**6)
prf.print_stats()
print(len(self.x), math.log10((len(self.x))))
self.plot_timecorse_of_move(show_it=1)
示例4: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def profiled_func(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(func)
profiler.enable_by_count()
return func(*args, **kwargs)
finally:
profiler.print_stats()
示例5: wrapped_fn
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def wrapped_fn(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(fn)
for f in follow:
profiler.add_function(f)
profiler.enable_by_count()
return fn(*args, **kwargs)
finally:
profiler.print_stats()
示例6: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def profiled_func(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(func)
for f in follow:
profiler.add_function(getattr(args[0], f))
profiler.enable_by_count()
return func(*args, **kwargs)
finally:
profiler.print_stats()
示例7: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def profiled_func(*args, **kwargs):
try:
pf = LineProfiler()
pf.add_function(func)
for f in follow:
pf.add_function(f)
pf.enable_by_count()
return func(*args, **kwargs)
finally:
pf.print_stats()
示例8: profile_on
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def profile_on(fcn_names=None):
if fcn_names and HAS_LINE_PROFILER:
pr = LineProfiler()
for fcn_name in fcn_names:
pr.add_function(fcn_name)
pr.enable()
return pr
pr = cProfile.Profile()
pr.enable()
return pr
示例9: timetest
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def timetest(func, *para):
p = LineProfiler()
p.add_function(func)
p.enable_by_count()
p_wrapper = p(func)
p_wrapper(*para)
# Printing
print(func(*para))
p.print_stats()
示例10: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def profiled_func(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(func)
for f in follow:
if isinstance(f, basestring):
f = to_function(f)
profiler.add_function(f)
profiler.enable_by_count()
return func(*args, **kwargs)
finally:
profiler.print_stats()
示例11: speedtest_validate_transaction
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def speedtest_validate_transaction():
# create a transaction
b = bigchaindb.Bigchain()
tx = b.create_transaction(b.me, b.me, None, 'CREATE')
tx_signed = b.sign_transaction(tx, b.me_private)
# setup the profiler
profiler = LineProfiler()
profiler.enable_by_count()
profiler.add_function(bigchaindb.Bigchain.validate_transaction)
# validate_transaction 1000 times
for i in range(1000):
b.validate_transaction(tx_signed)
profiler.print_stats()
示例12: Profiler
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
class Profiler(object):
def __init__(self, *args):
self.profile = LineProfiler()
if len(args) > 0:
for func in args:
if callable(func):
self.add_function(func)
def add_function(self, func):
self.profile.add_function(func)
def __enter__(self):
self.profile.enable_by_count()
def __exit__(self, type, value, traceback):
self.profile.disable_by_count()
self.profile.print_stats()
示例13: run_profiling
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
def run_profiling(args):
lprofiler = LineProfiler()
monitor_fuctions = [api.problem.submit_key, api.problem.get_unlocked_pids, api.problem.get_solved_pids,
api.problem.get_all_problems, api.problem.get_solved_problems, api.stats.get_score,
api.cache.memoize, api.autogen.grade_problem_instance, api.autogen.get_problem_instance,
api.autogen.get_number_of_instances]
for func in monitor_fuctions:
lprofiler.add_function(func)
lprofiler.enable()
if args.stack:
profiler = Profiler(use_signal=False)
profiler.start()
for func, a, kw in operations:
func(*a, **kw)
if args.stack:
profiler.stop()
lprofiler.disable()
if args.print:
print(profiler.output_text(unicode=True, color=True))
lprofiler.print_stats()
output = open(args.output, "w")
if args.stack:
output.write(profiler.output_text(unicode=True))
if args.output_html is not None:
output_html = open(args.output_html, "w")
output_html.write(profiler.output_html())
output_html.close()
print("Wrote test info to " + args.output_html)
lprofiler.print_stats(output)
output.close()
print("Wrote test info to " + args.output)
示例14: zip
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
for timestamp in bit_2_events[-5:]:
print "unstrobed bit 2 t=%f" % timestamp
print "found %d bit 3 events. Last 5 events are:" %(len(bit_3_events))
for timestamp in bit_3_events[-5:]:
print "unstrobed bit 3 t=%f" % timestamp
unstrobed_word = pu.GetExtEvents(data, event='unstrobed_word', online=False)
print "found %d unstrobed word events in which 10 events are:" %(len(unstrobed_word['value']))
indices = np.arange(0,len(unstrobed_word['value']),len(unstrobed_word['value'])/10)
for value,timestamp in zip(unstrobed_word['value'][indices],unstrobed_word['timestamp'][indices]) :
binary_value = bin(value)
print "unstrobed word:%s t=%f" % (binary_value,timestamp)
if __name__ == "__main__":
#run()
profile = LineProfiler()
profile.add_function(run)
profile.add_function(PlexUtil.GetExtEvents)
profile.add_function(reconstruct_word)
profile.run('run()')
profile.print_stats()
profile.dump_stats("testPlexFile_profile.lprof")
#cProfile.run('run()','PlexFile_profile')
#p = pstats.Stats('testPlexFile_profile.lprof')
#p.sort_stats('cumulative')
#p.print_stats()
#print h.heap()
示例15: DFMessage
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import add_function [as 别名]
m = DFMessage(fmt, elements, False)
except ValueError:
return self._parse_next()
self._add_msg(m)
return m
if __name__ == "__main__":
import sys
use_profiler = False
if use_profiler:
from line_profiler import LineProfiler
profiler = LineProfiler()
profiler.add_function(DFReader_binary._parse_next)
profiler.add_function(DFReader_binary._add_msg)
profiler.add_function(DFReader._set_time)
profiler.enable_by_count()
filename = sys.argv[1]
if filename.endswith('.log'):
log = DFReader_text(filename)
else:
log = DFReader_binary(filename)
while True:
m = log.recv_msg()
if m is None:
break
#print(m)
if use_profiler: