Debian Codegraph @

debian/patches/test_timing_precision.patch

raw
1 Index: dolfin/python/test/unit/common/test_timer.py
2 ===================================================================
3 --- dolfin.orig/python/test/unit/common/test_timer.py 2024-01-04 02:03:57.161702192 +0100
4 +++ dolfin/python/test/unit/common/test_timer.py 2024-01-04 02:04:43.060998594 +0100
5 @@ -29,6 +29,10 @@
6 # Seed random generator for determinism
7 random.seed(0)
8
9 +# resolution of the timer is not precise,
10 +# need to allow some tolerance
11 +timing_resolution = 0.015
12 +
13 def get_random_task_name():
14 """Get pseudo-random string"""
15 return hex(random.randint(0, 1e32))
16 @@ -40,20 +44,20 @@
17
18 # Execute task in the context manager
19 with Timer(task) as t:
20 - sleep(0.05)
21 - assert t.elapsed()[0] >= 0.05
22 + sleep(0.1)
23 + assert t.elapsed()[0] >= 0.1 - timing_resolution
24
25 # Check timing
26 t = timing(task, TimingClear.clear)
27 assert t[0] == 1
28 - assert t[1] >= 0.05
29 + assert t[1] >= 0.05 - timing_resolution
30
31
32 def test_context_manager_anonymous():
33 """Test that anonymous Timer works as context manager"""
34 with Timer() as t:
35 - sleep(0.05)
36 - assert t.elapsed()[0] >= 0.05
37 + sleep(0.1)
38 + assert t.elapsed()[0] >= 0.1 - timing_resolution
39
40
41 # Test case for decorated free function
42 @@ -116,7 +120,7 @@
43 # Check that correct timing was recorded
44 t = timing(task, TimingClear.clear)
45 assert t[0] == 2
46 - assert t[1] >= 0.1
47 + assert t[1] >= 0.1 - timing_resolution
48
49
50 def test_decorator_timer_scope():
51 @@ -158,4 +162,4 @@
52 sleep(0.05)
53
54 # Check that sleeping above did not influence timer
55 - assert timing(task, TimingClear.clear)[1] < 0.1
56 + assert timing(task, TimingClear.clear)[1] < 0.1 + timing_resolution