diff --git a/Mesa/Flocking/benchmark.py b/Mesa/Flocking/benchmark.py index a778f72a..0f25396d 100644 --- a/Mesa/Flocking/benchmark.py +++ b/Mesa/Flocking/benchmark.py @@ -5,9 +5,16 @@ import timeit import gc import statistics +import random -setup = f""" -gc.enable() +REPETITIONS = 3 +SEED = 12 + +random.seed(SEED) +a = [] +for i in range(0, REPETITIONS): + tt = timeit.Timer('runthemodel(flock)', setup= +f"""gc.enable() import os, sys sys.path.insert(0, os.path.abspath(".")) @@ -21,13 +28,12 @@ def runthemodel(flock): flock = BoidFlockers( population=80000, width=400, - height=400 + height=400, + seed={random.randint(0, 999999999)} ) """ - -tt = timeit.Timer('runthemodel(flock)', setup=setup) -SAMPLES=3 -a = tt.repeat(SAMPLES, 1) + ) + a.append(tt.timeit(1)) print("Mesa Flocking times (ms):", list(map(lambda x: x * 1e3, a))) print("Mesa Flocking (mean ms):", statistics.mean(a)*1e3)