plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
389dc0f
— Peter John
2026-11-10T22:31:03+05:30
benchmarks/scene_trees: the branch alone by default; its program takes arguments
benchmarks/scene_trees/run.py
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
|
-
"""Times the persistent scene tree on this branch against master's three
|
|
2
|
+
"""Times the persistent scene tree on this branch, on its own or against master's three
|
|
3
|
+
scene trees.
|
|
3
4
|
|
|
4
|
-
usage: python3 benchmarks/scene_trees/run.py
|
|
5
|
+
usage: python3 benchmarks/scene_trees/run.py [--runs 5] [--sizes 100,1000,10000]
|
|
5
6
|
[--workloads 1,...,11] [--out target/scene_trees]
|
|
7
|
+
[--plum target/debug/plum]
|
|
6
|
-
[--
|
|
8
|
+
[--master DIR [--master-plum DIR/target/debug/plum]]
|
|
7
9
|
|
|
8
|
-
Run from the repository root of this branch, after `cargo build -p plum-cli`.
|
|
10
|
+
Run from the repository root of this branch, after `cargo build -p plum-cli`. By default
|
|
11
|
+
only the branch's three builds run (a quick run: `--runs 1 --sizes 100,1000`). With
|
|
9
|
-
a checkout of master (e0ccfc7 or later) with its compiler built
|
|
12
|
+
`--master`, a checkout of master (e0ccfc7 or later) with its compiler built
|
|
13
|
+
(`cargo build -p plum-cli` there), master's three programs run too; a copy made with
|
|
10
|
-
|
|
14
|
+
`git archive` works, and keeps the build out of your own master checkout:
|
|
11
|
-
checkout:
|
|
12
15
|
|
|
13
16
|
mkdir -p target/master-src
|
|
14
17
|
git archive e0ccfc7 | tar -x -C target/master-src # from a clone that has master
|
|
@@ -25,11 +28,9 @@ Versions:
|
|
|
25
28
|
|
|
26
29
|
Each is built once with `plum build` (a native executable that runs the wasm under
|
|
27
30
|
wasmtime). Then every (workload, N, version) runs once per round, in a rotated order, for
|
|
28
|
-
`--runs` rounds, each a fresh process.
|
|
31
|
+
`--runs` rounds, each a fresh process. Every program takes the workload and N as
|
|
29
|
-
arguments and
|
|
32
|
+
arguments and times with the microsecond clock. The table gives the median ms with the
|
|
30
|
-
`scene_trees.args` in its working folder and times with the branch's whole-ms clock. The
|
|
31
|
-
table gives the median ms with the range, and fails if two runs that should agree print
|
|
32
|
-
different checksums. Workloads 8 and 9 (snapshots kept) only run on the persistent trees,
|
|
33
|
+
range, and fails if two runs that should agree print different checksums. Workloads 8 and 9 (snapshots kept) only run on the persistent trees,
|
|
33
34
|
and 10 and 11 (mostly still: 1% of the leaves move, spread over the groups or all in one)
|
|
34
35
|
only on the branch: master's programs have no still leaves.
|
|
35
36
|
"""
|
|
@@ -62,7 +63,7 @@ def build(plum, src, exe, flags, cwd, lib=None):
|
|
|
62
63
|
|
|
63
64
|
def main():
|
|
64
65
|
ap = argparse.ArgumentParser()
|
|
65
|
-
ap.add_argument("--master",
|
|
66
|
+
ap.add_argument("--master", help="a built checkout of master, to compare against")
|
|
66
67
|
ap.add_argument("--runs", type=int, default=5)
|
|
67
68
|
ap.add_argument("--sizes", default="100,1000,10000")
|
|
68
69
|
ap.add_argument("--workloads", default="1,2,3,4,5,6,7,8,9,10,11")
|
|
@@ -70,21 +71,26 @@ def main():
|
|
|
70
71
|
ap.add_argument("--plum", default="target/debug/plum", help="this branch's compiler")
|
|
71
72
|
ap.add_argument("--master-plum", help="master's compiler (default: DIR/target/debug/plum)")
|
|
72
73
|
args = ap.parse_args()
|
|
73
|
-
|
|
74
|
+
if args.master_plum and not args.master:
|
|
74
|
-
|
|
75
|
+
sys.exit("--master-plum needs --master")
|
|
75
76
|
plum = os.path.abspath(args.plum)
|
|
76
77
|
out = os.path.abspath(args.out)
|
|
77
78
|
os.makedirs(out, exist_ok=True)
|
|
78
79
|
exes = {}
|
|
80
|
+
masters = []
|
|
81
|
+
if args.master:
|
|
82
|
+
master = os.path.abspath(args.master)
|
|
83
|
+
mplum = os.path.abspath(args.master_plum) if args.master_plum else os.path.join(master, "target/debug/plum")
|
|
79
|
-
|
|
84
|
+
for v in ("game", "game_tree"):
|
|
80
|
-
|
|
85
|
+
exes[v] = os.path.join(out, "m_" + v)
|
|
81
|
-
|
|
86
|
+
build(mplum, os.path.join(master, "benchmarks/scene_trees", v + ".plum"), exes[v], [], master)
|
|
82
|
-
|
|
87
|
+
exes["enum_tree"] = os.path.join(out, "m_enum_tree")
|
|
83
|
-
|
|
88
|
+
build(mplum, os.path.join(HERE, "master/game_enum_tree_kept.plum"), exes["enum_tree"], [], master, master)
|
|
89
|
+
masters = MASTER
|
|
84
90
|
for name, flags in BRANCH:
|
|
85
91
|
exes[name] = os.path.join(out, "b" + "".join(flags).replace("-", "_"))
|
|
86
92
|
build(plum, os.path.join(HERE, "scene_tree.plum"), exes[name], flags, ".")
|
|
87
|
-
versions =
|
|
93
|
+
versions = masters + [b for b, _ in BRANCH]
|
|
88
94
|
sizes = [int(x) for x in args.sizes.split(",")]
|
|
89
95
|
workloads = [int(x) for x in args.workloads.split(",")]
|
|
90
96
|
cells = [(w, n) for w in workloads for n in sizes]
|
|
@@ -94,20 +100,16 @@ def main():
|
|
|
94
100
|
vs = [v for v in versions if (w < 8 or v not in ("game", "game_tree")) and (w < 10 or v not in MASTER)]
|
|
95
101
|
k = r % len(vs)
|
|
96
102
|
for v in vs[k:] + vs[:k]:
|
|
97
|
-
if v in MASTER:
|
|
98
|
-
|
|
103
|
+
res = subprocess.run([exes[v], str(w), str(n)], check=True, capture_output=True, text=True, cwd=out)
|
|
99
|
-
else:
|
|
100
|
-
with open(os.path.join(out, "scene_trees.args"), "w") as f:
|
|
101
|
-
f.write(f"{w} {n}\n")
|
|
102
|
-
res = subprocess.run([exes[v]], check=True, capture_output=True, text=True, cwd=out)
|
|
103
104
|
m = re.search(r"w(\d+) n(\d+) ms (\S+) checksum (\S+)", res.stdout)
|
|
104
105
|
if not m or (int(m.group(1)), int(m.group(2))) != (w, n):
|
|
105
106
|
sys.exit(f"no result from {v} w{w} n{n}: {res.stdout!r}")
|
|
106
107
|
times.setdefault((w, n, v), []).append(float(m.group(3)))
|
|
107
108
|
sums.setdefault((w, n), set()).add(m.group(4))
|
|
108
109
|
print(f"round {r + 1}: {WORKLOADS[w]} N={n} done", file=sys.stderr)
|
|
110
|
+
ratio = " branch / enum_tree |" if masters else ""
|
|
109
|
-
print("| workload | N | " + " | ".join(versions) + " |
|
|
111
|
+
print("| workload | N | " + " | ".join(versions) + " |" + ratio + " checksum |")
|
|
110
|
-
print("|---|---|" + "---|" * (len(versions) + 2))
|
|
112
|
+
print("|---|---|" + "---|" * (len(versions) + (2 if masters else 1)))
|
|
111
113
|
for w, n in cells:
|
|
112
114
|
row = f"| {WORKLOADS[w]} | {n} |"
|
|
113
115
|
for v in versions:
|
|
@@ -116,9 +118,10 @@ def main():
|
|
|
116
118
|
row += " - |"
|
|
117
119
|
continue
|
|
118
120
|
row += f" {fmt(statistics.median(ts))} ({fmt(min(ts))}-{fmt(max(ts))}) |"
|
|
121
|
+
if masters:
|
|
119
|
-
|
|
122
|
+
e = statistics.median(times[(w, n, "enum_tree")]) if (w, n, "enum_tree") in times else 0
|
|
120
|
-
|
|
123
|
+
b = statistics.median(times[(w, n, "branch")])
|
|
121
|
-
|
|
124
|
+
row += f" {b / e:.2f}x |" if e > 0 else " - |"
|
|
122
125
|
row += f" {', '.join(sorted(sums[(w, n)]))} |"
|
|
123
126
|
print(row)
|
|
124
127
|
bad = [(w, n, s) for (w, n), s in sums.items() if len(s) != 1]
|
benchmarks/scene_trees/scene_tree.plum
CHANGED
|
@@ -3,7 +3,6 @@ import std/Float
|
|
|
3
3
|
import std/Bool
|
|
4
4
|
import std/Str
|
|
5
5
|
import std/Io
|
|
6
|
-
import std/Os
|
|
7
6
|
import std/Option
|
|
8
7
|
import std/Result
|
|
9
8
|
import std/collections/List
|
|
@@ -24,9 +23,8 @@ import std/game/SceneTree
|
|
|
24
23
|
# master's three programs and prints the same checksums; see
|
|
25
24
|
# docs/benchmarks/2026-11-08-scene-trees-branch.md and run.py.
|
|
26
25
|
#
|
|
27
|
-
#
|
|
26
|
+
# It takes the workload and N as arguments, as master's do (`scene_tree 4 1000`); without
|
|
28
|
-
# file, `scene_trees.args` in the current folder ("<workload> <N>"); without it, it runs
|
|
29
|
-
# workloads 1 to 4 at N = 100.
|
|
27
|
+
# them it runs workloads 1 to 4 at N = 100. It times with the microsecond clock.
|
|
30
28
|
#
|
|
31
29
|
# The scene: a root, 10 groups (moved, scaled and turned), and N - 11 leaves, 20 by 20
|
|
32
30
|
# rectangles, spread over the groups in turn. Workloads (the numbers are master's):
|
|
@@ -295,14 +293,14 @@ fun work(stage: SceneTree<Int>, sc: Bench, w: Int, n: Int) -> Int =
|
|
|
295
293
|
fun run(io: Io, w: Int, n: Int) -> Int =
|
|
296
294
|
sc := bench(n)
|
|
297
295
|
stage := build(n, sc, w)
|
|
298
|
-
t0 := io.
|
|
296
|
+
t0 := io.nowMicros()
|
|
299
297
|
sum := work(stage, sc, w, n)
|
|
300
|
-
ms := io.
|
|
298
|
+
ms := {io.nowMicros() - t0} / 1000.0
|
|
301
299
|
io.printLn("scene_tree w{w} n{n} ms {ms} checksum {sum}")
|
|
302
300
|
sum
|
|
303
301
|
|
|
304
302
|
fun main(io: Io) =
|
|
305
|
-
args :=
|
|
303
|
+
args := io.args()
|
|
306
304
|
if args.length() == 2
|
|
307
305
|
_ := run(io, Int.parse(args.at(0)).unwrapOr(1), Int.parse(args.at(1)).unwrapOr(100))
|
|
308
306
|
else
|
docs/benchmarks/2026-11-08-scene-trees-branch.md
CHANGED
|
@@ -152,8 +152,8 @@ git archive e0ccfc7 | tar -x -C target/master-src # from a clone that has ma
|
|
|
152
152
|
(cd target/master-src && cargo build -p plum-cli)
|
|
153
153
|
python3 benchmarks/scene_trees/run.py --master target/master-src # 5 rounds; --runs, --sizes, --workloads 1,...,9
|
|
154
154
|
target/debug/plum test benchmarks/scene_trees # master's checksums at N = 100, all nine workloads
|
|
155
|
-
|
|
155
|
+
target/debug/plum build benchmarks/scene_trees/scene_tree.plum -o target/st && target/st 1 10000 # one cell
|
|
156
|
-
target/debug/plum build --explain-fusion benchmarks/scene_trees/
|
|
156
|
+
target/debug/plum build --explain-fusion benchmarks/scene_trees/scene_tree.plum -o target/st # the proof's reasons
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
`run.py` builds each version once with `plum build` (a native executable running the wasm under wasmtime, with the runtime built in release), runs every (workload, N, version) once per round in a rotated order, each a fresh process, and fails if two runs of a cell print different checksums.
|
|
159
|
+
`run.py` builds each version once with `plum build` (a native executable running the wasm under wasmtime, with the runtime built in release), runs every (workload, N, version) once per round in a rotated order, each a fresh process, and fails if two runs of a cell print different checksums. (When this was measured the branch's program read the workload and N from a file, `scene_trees.args`, and timed itself in whole ms; it now takes them as arguments and times with `io.nowMicros()`, as master's do, and `run.py` runs the branch alone unless given `--master`.) A full run of five rounds took about 12 minutes here.
|