|
1 | | - |
2 | 1 | import os |
3 | | -import time |
| 2 | +import subprocess |
4 | 3 | import sys |
| 4 | +from pathlib import Path |
5 | 5 |
|
6 | 6 | import pytest |
7 | | -import subprocess |
| 7 | + |
| 8 | +ROOT = Path(__file__).resolve().parent.parent |
| 9 | +BENCHES = ROOT / "benches" |
8 | 10 |
|
9 | 11 | # Interpreters: |
10 | | -rustpython_exe = '../target/release/rustpython' |
| 12 | +default_rustpython = ( |
| 13 | + ROOT |
| 14 | + / "target" |
| 15 | + / "release" |
| 16 | + / ("rustpython.exe" if os.name == "nt" else "rustpython") |
| 17 | +) |
| 18 | +rustpython_exe = str(Path(os.environ.get("RUSTPYTHON", default_rustpython)).resolve()) |
11 | 19 | cpython_exe = sys.executable |
12 | | -pythons = [ |
13 | | - cpython_exe, |
14 | | - rustpython_exe |
15 | | -] |
| 20 | +pythons = [cpython_exe, rustpython_exe] |
16 | 21 |
|
17 | 22 | # Benchmark scripts: |
18 | 23 | benchmarks = [ |
19 | | - ['benchmarks/nbody.py'], |
20 | | - ['benchmarks/mandelbrot.py'], |
21 | | - ['benchmarks/strings.py'], |
| 24 | + BENCHES / "benchmarks" / "nbody.py", |
| 25 | + BENCHES / "benchmarks" / "mandelbrot.py", |
| 26 | + BENCHES / "microbenchmarks" / "strings.py", |
22 | 27 | ] |
23 | 28 |
|
24 | | -exe_ids = ['cpython', 'rustpython'] |
25 | | -benchmark_ids = [benchmark[0].split('/')[-1] for benchmark in benchmarks] |
26 | | - |
27 | | -@pytest.mark.parametrize('exe', pythons, ids=exe_ids) |
28 | | -@pytest.mark.parametrize('args', benchmarks, ids=benchmark_ids) |
29 | | -def test_bench(exe, args, benchmark): |
30 | | - def bench(): |
31 | | - subprocess.run([exe] + args) |
| 29 | +exe_ids = ["cpython", "rustpython"] |
| 30 | +benchmark_ids = [benchmark.name for benchmark in benchmarks] |
32 | 31 |
|
33 | | - benchmark(bench) |
34 | 32 |
|
| 33 | +@pytest.mark.parametrize("exe", pythons, ids=exe_ids) |
| 34 | +@pytest.mark.parametrize("script", benchmarks, ids=benchmark_ids) |
| 35 | +def test_bench(exe, script, benchmark): |
| 36 | + benchmark(subprocess.run, [exe, str(script)], cwd=ROOT, check=True) |
0 commit comments