Skip to content

Commit 47269f7

Browse files
committed
TEST potentially fix brittle stopwatch test
1 parent a18c631 commit 47269f7

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

test/test_util/test_StopWatch.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import print_function
1010
import time
1111
import unittest
12+
import unittest.mock
1213

1314
from autosklearn.util import StopWatch
1415

@@ -17,29 +18,24 @@ class Test(unittest.TestCase):
1718
_multiprocess_can_split_ = True
1819

1920
def test_stopwatch_overhead(self):
20-
# CPU overhead
21-
start = time.clock()
22-
watch = StopWatch()
23-
for i in range(1, 1000):
24-
watch.start_task('task_%d' % i)
25-
watch.stop_task('task_%d' % i)
26-
stop = time.clock()
27-
dur = stop - start
28-
cpu_overhead = dur - watch.cpu_sum()
29-
self.assertLess(cpu_overhead, 1.5)
3021

3122
# Wall Overhead
3223
start = time.time()
24+
cpu_start = time.clock()
3325
watch = StopWatch()
3426
for i in range(1, 1000):
3527
watch.start_task('task_%d' % i)
3628
watch.stop_task('task_%d' % i)
29+
cpu_stop = time.clock()
3730
stop = time.time()
3831
dur = stop - start
32+
cpu_dur = cpu_stop - cpu_start
33+
cpu_overhead = cpu_dur - watch.cpu_sum()
3934
wall_overhead = dur - watch.wall_sum()
4035

41-
self.assertLess(wall_overhead, 2)
42-
self.assertLess(cpu_overhead, 2*wall_overhead)
36+
self.assertLess(cpu_overhead, 1)
37+
self.assertLess(wall_overhead, 1)
38+
self.assertLess(watch.cpu_sum(), 2 * watch.wall_sum())
4339

4440

4541
if __name__ == '__main__':

0 commit comments

Comments
 (0)