Skip to content

Commit

Permalink
faster perf tests, retry perf tests on except
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jun 2, 2016
1 parent 8b5a87e commit f492111
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions tqdm/tests/tests_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def cpu_sleep(t):

def checkCpuTime(sleeptime=0.2):
'''Check if cpu time works correctly'''
if checkCpuTime.passed:
return True
# First test that sleeping does not consume cputime
start1 = process_time()
sleep(sleeptime)
Expand All @@ -43,7 +45,10 @@ def checkCpuTime(sleeptime=0.2):
cpu_sleep(sleeptime)
t2 = process_time() - start2

return (abs(t1) < 0.0001 and (t1 < t2 / 10))
if (abs(t1) < 0.0001 and (t1 < t2 / 10)):
return True
raise SkipTest
checkCpuTime.passed = False


@contextmanager
Expand All @@ -60,6 +65,23 @@ def elapser(): # NOQA
return spent


def retry_on_except(n=3):
def wrapper(fn):
def test_inner():
for i in range(1, n + 1):
try:
checkCpuTime()
fn()
except:
if i >= n:
raise
else:
return
test_inner.__doc__ = fn.__doc__
return test_inner
return wrapper


class MockIO(StringIO):
""" Wraps StringIO to mock a file with no I/O """
def write(self, data):
Expand Down Expand Up @@ -132,12 +154,9 @@ def update_and_yield():


@with_setup(pretest, posttest)
@retry_on_except()
def test_iter_overhead():
""" Test overhead of iteration based tqdm """
try:
assert checkCpuTime()
except:
raise SkipTest

total = int(1e6)

Expand All @@ -161,12 +180,9 @@ def test_iter_overhead():


@with_setup(pretest, posttest)
@retry_on_except()
def test_manual_overhead():
""" Test overhead of manual tqdm """
try:
assert checkCpuTime()
except:
raise SkipTest

total = int(1e6)

Expand All @@ -191,12 +207,9 @@ def test_manual_overhead():


@with_setup(pretest, posttest)
@retry_on_except()
def test_iter_overhead_hard():
""" Test overhead of iteration based tqdm (hard) """
try:
assert checkCpuTime()
except:
raise SkipTest

total = int(1e5)

Expand All @@ -223,12 +236,9 @@ def test_iter_overhead_hard():


@with_setup(pretest, posttest)
@retry_on_except()
def test_manual_overhead_hard():
""" Test overhead of manual tqdm (hard) """
try:
assert checkCpuTime()
except:
raise SkipTest

total = int(1e5)

Expand Down Expand Up @@ -256,12 +266,9 @@ def test_manual_overhead_hard():


@with_setup(pretest, posttest)
@retry_on_except()
def test_iter_overhead_simplebar_hard():
""" Test overhead of iteration based tqdm vs simple progress bar (hard) """
try:
assert checkCpuTime()
except:
raise SkipTest

total = int(1e4)

Expand Down Expand Up @@ -290,12 +297,9 @@ def test_iter_overhead_simplebar_hard():


@with_setup(pretest, posttest)
@retry_on_except()
def test_manual_overhead_simplebar_hard():
""" Test overhead of manual tqdm vs simple progress bar (hard) """
try:
assert checkCpuTime()
except:
raise SkipTest

total = int(1e4)

Expand Down

0 comments on commit f492111

Please sign in to comment.