import subprocess, sys from time import time RUNS = 5 LOOPS = 100 ARGS = [sys.executable, '-c', 'pass'] def bench(env): best = None for run in range(RUNS): print("%s/%s" % (run, RUNS)) a = time() for loop in range(LOOPS): subprocess.call(ARGS, env=env) b = time() dt = float(b - a) / LOOPS if best is not None: best = min(best, dt) else: best = dt return best a = bench(None) b = bench({'PYTHONHASHSEED': '0'}) a *= 1000 b *= 1000 print("%.1f ms (random) vs %.1f ms (const)" % (a, b)) dt = a - b print("Overhead: %.1f ms (%.0f%%)" % (dt, dt * 100. / b))