本文整理匯總了Python中timeit.main方法的典型用法代碼示例。如果您正苦於以下問題:Python timeit.main方法的具體用法?Python timeit.main怎麽用?Python timeit.main使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類timeit
的用法示例。
在下文中一共展示了timeit.main方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import timeit [as 別名]
# 或者: from timeit import main [as 別名]
def main():
print "unidecode_expect_ascii, ASCII string"
timeit.main([
'-s',
'from unidecode import unidecode_expect_ascii',
'unidecode_expect_ascii(u"Hello, World")'])
print "unidecode_expect_ascii, non-ASCII string"
timeit.main([
'-s',
'from unidecode import unidecode_expect_ascii',
'unidecode_expect_ascii(u"¡Hola mundo!")'])
print "unidecode_expect_nonascii, ASCII string"
timeit.main([
'-s',
'from unidecode import unidecode_expect_nonascii',
'unidecode_expect_nonascii(u"Hello, World")'])
print "unidecode_expect_nonascii, non-ASCII string"
timeit.main([
'-s',
'from unidecode import unidecode_expect_nonascii',
'unidecode_expect_nonascii(u"¡Hola mundo!")'])
示例2: run_main
# 需要導入模塊: import timeit [as 別名]
# 或者: from timeit import main [as 別名]
def run_main(self, seconds_per_increment=1.0, switches=None, timer=None):
if timer is None:
timer = FakeTimer(seconds_per_increment=seconds_per_increment)
if switches is None:
args = []
else:
args = switches[:]
args.append(self.fake_stmt)
# timeit.main() modifies sys.path, so save and restore it.
orig_sys_path = sys.path[:]
with captured_stdout() as s:
timeit.main(args=args, _wrap_timer=timer.wrap_timer)
sys.path[:] = orig_sys_path[:]
return s.getvalue()