Format scripts

This commit is contained in:
Victor Zverovich committed 2016-06-15 16:15:34 -07:00
1 parent e9a0d3141b
commit 41356aa00a
7 files changed
+233 -228

No files matched your search

+24 -24
View File
@@ -5,31 +5,31 @@ from contextlib import contextmanager
import timeit
class Timer:
"""
A with statement based timer.
Usage:
t = Timer()
with t:
do_something()
time = t.time
"""
def __enter__(self):
self.start = timeit.default_timer()
"""
A with statement based timer.
Usage:
t = Timer()
with t:
do_something()
time = t.time
"""
def __exit__(self, type, value, traceback):
finish = timeit.default_timer()
self.time = finish - self.start
def __enter__(self):
self.start = timeit.default_timer()
def __exit__(self, type, value, traceback):
finish = timeit.default_timer()
self.time = finish - self.start
@contextmanager
def print_time(*args):
"""
Measures and prints the time taken to execute nested code.
args: Additional arguments to print.
"""
t = Timer()
print(*args)
with t:
yield
print(*args, end=' ')
print('finished in {0:.2f} second(s)'.format(t.time))
"""
Measures and prints the time taken to execute nested code.
args: Additional arguments to print.
"""
t = Timer()
print(*args)
with t:
yield
print(*args, end=' ')
print('finished in {0:.2f} second(s)'.format(t.time))