Skip to content

Commit

Permalink
seed mesa (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Dec 11, 2023
1 parent ac174f2 commit 6f0672a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
18 changes: 12 additions & 6 deletions Mesa/Flocking/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
import timeit
import gc
import statistics
import random

setup = f"""
REPETITIONS = 3
SEED = 12

random.seed(SEED)
a = []
for i in range(0, REPETITIONS):
setup=f"""
gc.enable()
import os, sys
sys.path.insert(0, os.path.abspath("."))
Expand All @@ -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)
tt = timeit.Timer('runthemodel(flock)', setup=setup)
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)

21 changes: 12 additions & 9 deletions Mesa/Schelling/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@
import timeit
import gc
import statistics
import random

REPETITIONS = 3
SEED = 12

setup = f"""
random.seed(SEED)
a = []
for i in range(0, REPETITIONS):
setup = f"""
gc.enable()
import os, sys
sys.path.insert(0, os.path.abspath("."))
from model import SchellingModel
import random
random.seed(2)
def runthemodel(schelling):
for i in range(0, 100):
schelling.step()
schelling = SchellingModel(
height=500,
width=500,
density=0.8
density=0.8,
seed={random.randint(0, 999999999)}
)
"""

tt = timeit.Timer('runthemodel(schelling)', setup=setup)
SAMPLES=3
a = tt.repeat(SAMPLES, 1)
tt = timeit.Timer('runthemodel(schelling)', setup=setup)
a.append(tt.timeit(1))
print("Mesa schelling times (ms):", list(map(lambda x: x * 1e3, a)))
print("Mesa schelling (mean ms):", statistics.mean(a)*1e3)

Expand Down

0 comments on commit 6f0672a

Please sign in to comment.