本文整理汇总了Python中line_profiler.LineProfiler.disable方法的典型用法代码示例。如果您正苦于以下问题:Python LineProfiler.disable方法的具体用法?Python LineProfiler.disable怎么用?Python LineProfiler.disable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类line_profiler.LineProfiler
的用法示例。
在下文中一共展示了LineProfiler.disable方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: profile_list_serialization
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import disable [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()
示例2: profile_list_deserialization
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import disable [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()
示例3: main
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import disable [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)
示例4: run_profiling
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import disable [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)
示例5: SpecialTestRunner
# 需要导入模块: from line_profiler import LineProfiler [as 别名]
# 或者: from line_profiler.LineProfiler import disable [as 别名]
class SpecialTestRunner(SpecialTest):
"""
Test runner, calls the specified test under specified profiler
Mode = None - no profiler, "c" - cProfile, "l" - LineProfiler, "h" - hotshot
"""
def __init__(self, test, mode=None):
super(SpecialTestRunner, self).__init__()
self.mode = mode
self.test = test
self.profiler = None
def setup(self):
if self.mode == 'c':
import cProfile
self.profiler = cProfile.Profile()
elif self.mode == 'l':
from line_profiler import LineProfiler
self.profiler = LineProfiler()
elif self.mode == 'h':
import hotshot
self.info['name'] = 'special.prof'
self.profiler = hotshot.Profile(self.info['name'])
self.test.setup()
def run(self):
if self.mode == 'c':
self.profiler.enable()
elif self.mode == 'l':
self.profiler.enable_by_count()
self.profiler.add_function(Handler.handle)
self.profiler.add_function(Condition.check_string_match)
self.profiler.add_function(Condition.check_function)
self.profiler.add_function(Condition.check_list)
t = Timer()
# Run itself
if self.mode == 'h':
self.profiler.runcall(self.test.run)
else:
self.test.run()
print('Test time: %s' % t.delta())
if self.mode == 'c':
import pstats
import StringIO
self.profiler.disable()
sio = StringIO.StringIO()
ps = pstats.Stats(self.profiler, stream=sio).sort_stats('time')
ps.print_stats()
print(sio.getvalue())
elif self.mode == 'h':
import hotshot.stats
print('Processing results...')
self.profiler.close()
name = self.info['name']
stats = hotshot.stats.load(name)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(50)
print('Run "hotshot2calltree -o %s.out %s" to generate the cachegrind file' % (name, name))
elif self.mode == 'l':
self.profiler.disable()
self.profiler.print_stats()