Skip to content

Commit 6f0672a

Browse files
committed
seed mesa (untested)
1 parent ac174f2 commit 6f0672a

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

Mesa/Flocking/benchmark.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55
import timeit
66
import gc
77
import statistics
8+
import random
89

9-
setup = f"""
10+
REPETITIONS = 3
11+
SEED = 12
12+
13+
random.seed(SEED)
14+
a = []
15+
for i in range(0, REPETITIONS):
16+
setup=f"""
1017
gc.enable()
1118
import os, sys
1219
sys.path.insert(0, os.path.abspath("."))
@@ -21,13 +28,12 @@ def runthemodel(flock):
2128
flock = BoidFlockers(
2229
population=80000,
2330
width=400,
24-
height=400
31+
height=400,
32+
seed={random.randint(0, 999999999)}
2533
)
2634
"""
27-
28-
tt = timeit.Timer('runthemodel(flock)', setup=setup)
29-
SAMPLES=3
30-
a = tt.repeat(SAMPLES, 1)
35+
tt = timeit.Timer('runthemodel(flock)', setup=setup)
36+
a.append(tt.timeit(1))
3137
print("Mesa Flocking times (ms):", list(map(lambda x: x * 1e3, a)))
3238
print("Mesa Flocking (mean ms):", statistics.mean(a)*1e3)
3339

Mesa/Schelling/benchmark.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,34 @@
33
import timeit
44
import gc
55
import statistics
6+
import random
7+
8+
REPETITIONS = 3
9+
SEED = 12
610

7-
setup = f"""
11+
random.seed(SEED)
12+
a = []
13+
for i in range(0, REPETITIONS):
14+
setup = f"""
815
gc.enable()
916
import os, sys
1017
sys.path.insert(0, os.path.abspath("."))
1118
1219
from model import SchellingModel
1320
14-
import random
15-
random.seed(2)
16-
1721
def runthemodel(schelling):
1822
for i in range(0, 100):
1923
schelling.step()
2024
2125
schelling = SchellingModel(
2226
height=500,
2327
width=500,
24-
density=0.8
28+
density=0.8,
29+
seed={random.randint(0, 999999999)}
2530
)
2631
"""
27-
28-
tt = timeit.Timer('runthemodel(schelling)', setup=setup)
29-
SAMPLES=3
30-
a = tt.repeat(SAMPLES, 1)
32+
tt = timeit.Timer('runthemodel(schelling)', setup=setup)
33+
a.append(tt.timeit(1))
3134
print("Mesa schelling times (ms):", list(map(lambda x: x * 1e3, a)))
3235
print("Mesa schelling (mean ms):", statistics.mean(a)*1e3)
3336

0 commit comments

Comments
 (0)