sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #04223
[Merge] ~bjornt/maas:perftests-no-gc-collect-noise into maas:master
Björn Tillenius has proposed merging ~bjornt/maas:perftests-no-gc-collect-noise into maas:master.
Commit message:
Control the garbage collection for the performance tests.
Before, one test could create a lot of garbage that then got
collected while running another test. That made the second test
look slower than it actually was.
Now we collect the garbage before a test being run, and also
collect it after the test is being run, including the last collection
in the timing of the test.
Requested reviews:
Alberto Donato (ack)
For more details, see:
https://code.launchpad.net/~bjornt/maas/+git/maas/+merge/435189
--
Your team MAAS Committers is subscribed to branch maas:master.
diff --git a/src/maastesting/pytest/perftest.py b/src/maastesting/pytest/perftest.py
index 7a9ce9b..491f889 100644
--- a/src/maastesting/pytest/perftest.py
+++ b/src/maastesting/pytest/perftest.py
@@ -6,6 +6,7 @@
from contextlib import contextmanager, ExitStack
from cProfile import Profile
+import gc
import json
import os
import sys
@@ -77,8 +78,18 @@ class Timing:
@contextmanager
def measure_time():
+ # Collect all the garbage before the timing begins,
+ # so that collection of unrelated garbage won't slow
+ # things down.
+ gc.collect()
timing = Timing()
yield timing
+ # Collect the garbage that was created by the code that is
+ # being timed, so that we get a more consistent timing.
+ # Otherwise, a small change to the code we time could cause
+ # a big change in time due to a new garbage collection being
+ # triggered.
+ gc.collect()
timing.stop()
References