Repository navigation
Expand file tree
/
Copy pathrun_all.py
More file actions
executable file
·38 lines (31 loc) · 2.59 KB
/
Copy pathrun_all.py
File metadata and controls
executable file
·38 lines (31 loc) · 2.59 KB
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
#!/usr/bin/env python3
# ════════════════════════════════════════════════════════════════
# FEAScript Benchmark
# Finite Element Simulation in JavaScript
# https://github.com/FEAScript/FEAScript-benchmark
# MIT License © 2026 FEAScript
# ════════════════════════════════════════════════════════════════
"""Run every benchmark for a FEAScript version: benchmarks, reports and the speed-up plots by version.
Build FEAScript-core first (npm run build), then run this with the Python that has the benchmark packages:
FEASCRIPT_VERSION=0.4.0 ~/.venvs/feascript-benchmark/bin/python run_all.py
Without FEASCRIPT_VERSION, the version comes from FEAScript-core/package.json. Add benchmark names to run only those.
"""
import json, os, re, subprocess, sys
HERE = os.path.dirname(os.path.abspath(__file__))
BENCHMARKS = ["heatConduction2DFin", "heatConduction2DFinGmsh", "creepingFlow2DLidDrivenCavity"]
HISTORY = ["heatConduction2DFin", "creepingFlow2DLidDrivenCavity"] # Benchmarks with results from several versions
core = os.path.abspath(os.environ.get("FEASCRIPT_CORE") or os.path.join(HERE, "..", "FEAScript-core"))
version = os.environ.get("FEASCRIPT_VERSION") or json.load(open(os.path.join(core, "package.json")))["version"]
cpu = subprocess.run("lscpu | sed -n 's/^Model name: *//p'", shell=True, capture_output=True, text=True).stdout.strip()
machine = os.environ.get("FEASCRIPT_MACHINE") or re.sub(r"[^a-z0-9]+", "-", re.sub(r"\((r|tm)\)|\d+-core processor", "", cpu.lower())).strip("-")
env = {**os.environ, "FEASCRIPT_VERSION": version, "FEASCRIPT_MACHINE": machine}
for bench in sys.argv[1:] or BENCHMARKS:
folder = os.path.join(HERE, bench)
run = os.path.join(folder, "reports", machine, version)
os.makedirs(run, exist_ok=True)
print(f"=== {bench}: FEAScript {version} on {machine}", flush=True)
with open(os.path.join(run, "run.log"), "a" if os.environ.get("ONLY_BROWSERS") else "w") as log: # A browser run adds to the log of the full run
subprocess.run([sys.executable, "benchmark.py"], cwd=folder, env=env, stdout=log, stderr=subprocess.STDOUT, check=True)
subprocess.run([sys.executable, "make_report.py", machine, version], cwd=folder, env=env, stdout=subprocess.DEVNULL, check=True)
if bench in HISTORY:
subprocess.run([sys.executable, os.path.join(HERE, "make_history.py"), bench], stdout=subprocess.DEVNULL, check=True)