forked from JuliaDynamics/ABMFrameworksComparison
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.py
More file actions
39 lines (30 loc) · 728 Bytes
/
benchmark.py
File metadata and controls
39 lines (30 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Use Python 3
# Only collect the number of wolves and sheeps per step.
import timeit
import gc
import statistics
import random
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("."))
from model import BoidFlockers
def runthemodel(flock):
for i in range(0, 100):
flock.step()
flock = BoidFlockers(
population=80000,
width=400,
height=400,
seed={random.randint(0, 999999999)}
)
"""
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)