perf: perform a garbage collection before each iteration
Currently, no explicit garbage collection is performed when running
the microbenchmarks in `hg perf`. I think this is wrong because
garbage collection can have a significant impact on execution times.
And, if gc is triggered via the default heuristics, it will
fire effectively randomly during subsequent benchmark iterations
due to variable amount of garbage left over from previous runs.
Running a gc before invoking the measured function will help ensure
state is more consistent across all iterations.
--- a/contrib/perf.py Mon Mar 13 18:31:29 2017 -0700
+++ b/contrib/perf.py Mon Mar 13 18:16:42 2017 -0700
@@ -20,6 +20,7 @@
from __future__ import absolute_import
import functools
+import gc
import os
import random
import sys
@@ -189,6 +190,7 @@
func()
def _timer(fm, func, title=None):
+ gc.collect()
results = []
begin = util.timer()
count = 0