本文整理汇总了Python中line_profiler.LineProfiler.print_stats方法的典型用法代码示例。如果您正苦于以下问题:Python LineProfiler.print_stats方法的具体用法?Python LineProfiler.print_stats怎么用?Python LineProfiler.print_stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类line_profiler.LineProfiler
的用法示例。
在下文中一共展示了LineProfiler.print_stats方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_lines
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [as 别名]
def profile_lines(self, functions, statement):
from line_profiler import LineProfiler
import __builtin__
profile = LineProfiler(*functions)
# Add the profiler to the builtins for @profile..
# will probably not work for all modules in ecoControl,
# as they are already imported before and @profile will then throw an error
if 'profile' in __builtin__.__dict__:
had_profile = True
old_profile = __builtin__.__dict__['profile']
else:
had_profile = False
old_profile = None
__builtin__.__dict__['profile'] = profile
try:
try:
profile.runctx(statement, globals(), locals())
message = ''
except SystemExit:
message = """*** SystemExit exception caught in code being profiled."""
except KeyboardInterrupt:
message = ("*** KeyboardInterrupt exception caught in code being "
"profiled.")
finally:
if had_profile:
__builtin__.__dict__['profile'] = old_profile
# Trap text output.
stdout_trap = StringIO()
profile.print_stats(stdout_trap)
output = stdout_trap.getvalue()
output = output.rstrip()
pfile = open("profile.txt", 'a')
pfile.write("\n\n" + 20 * "=" + "*********====================== profile at time " +
time.strftime("%b %d %Y %H:%M:%S", time.gmtime(time.time())) +
"==================================\n\n")
pfile.write(output)
pfile.close()
print '\n*** Profile printout saved to text file profile.txt', message
示例2: benchmark
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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
示例3: profile_list_deserialization
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [as 别名]
def profile_list_deserialization(serializer, child_serializer, data_list):
if os.environ.get('CI', None) != 'true' or not LineProfiler:
return
profile = LineProfiler(serializer.to_internal_value, child_serializer.to_internal_value)
profile.enable()
serializer.to_internal_value(data_list)
profile.disable()
profile.print_stats()
示例4: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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: profile_list_serialization
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [as 别名]
def profile_list_serialization(serializer, child_serializer, instances_list):
if os.environ.get('CI', None) != 'true' or not LineProfiler:
return
profile = LineProfiler(serializer.instances_list, child_serializer.instances_list)
profile.enable()
serializer.to_representation(instances_list)
profile.disable()
profile.print_stats()
示例6: DataReader_bin_test2
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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)
示例7: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例8: profile_each_line
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [as 别名]
def profile_each_line(func, *args, **kwargs):
profiler = LineProfiler()
profiled_func = profiler(func)
retval = None
try:
retval = profiled_func(*args, **kwargs)
finally:
profiler.print_stats()
return retval
示例9: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例10: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例11: wrapped_fn
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例12: timetest
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例13: profiled_func
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例14: speedtest_validate_transaction
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [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()
示例15: main
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import print_stats [as 别名]
def main():
profiler = cProfile.Profile()
profiler.enable()
function_runner('original_method')
function_runner('step_one')
function_runner('step_two')
function_runner('step_three')
function_runner('step_four')
function_runner('step_five')
function_runner('step_six')
function_runner('step_seven')
function_runner('step_eight')
function_runner('step_nine')
function_runner('current')
profiler.disable()
profiler.dump_stats('function_event.stats')
line_profiler = LineProfiler(CurrentFunctionContainer().current)
line_profiler.enable()
function_runner('current')
line_profiler.disable()
line_profiler.dump_stats('function_event.line_stats')
line_profiler.print_stats()
print 'Original', timeit.timeit(
lambda: function_runner('original_method'), number=7)
print 'One', timeit.timeit(
lambda: function_runner('step_one'), number=7)
print 'Two', timeit.timeit(
lambda: function_runner('step_two'), number=7)
print 'Three', timeit.timeit(
lambda: function_runner('step_three'), number=7)
print 'Four', timeit.timeit(
lambda: function_runner('step_four'), number=7)
print 'Five', timeit.timeit(
lambda: function_runner('step_five'), number=7)
print 'Six', timeit.timeit(
lambda: function_runner('step_six'), number=7)
print 'Seven', timeit.timeit(
lambda: function_runner('step_seven'), number=7)
print 'Eight', timeit.timeit(
lambda: function_runner('step_eight'), number=7)
print 'Nine', timeit.timeit(
lambda: function_runner('step_nine'), number=7)
print 'Current', timeit.timeit(
lambda: function_runner('current'), number=7)