plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


d94d0e1 — Peter John 2026-11-10T22:31:03+05:30
benchmarks/master_vs_simpler: the branch alone by default, master on request
Files changed (1) hide show
  1. benchmarks/master_vs_simpler/run.py +80 -48
benchmarks/master_vs_simpler/run.py CHANGED
@@ -1,14 +1,17 @@
1
1
  #!/usr/bin/env python3
2
- """Times master against simpler-language on ported programs: compile time, wasm size, run time.
2
+ """Times simpler-language on ported programs (compile time, wasm size, run time), on its own
3
+ or against master.
3
4
 
4
- usage: python3 benchmarks/master_vs_simpler/run.py --master DIR [--master-plum PATH] [--plum PATH]
5
+ usage: python3 benchmarks/master_vs_simpler/run.py [--plum PATH] [--runs 5] [--out target/master_vs_simpler]
6
+ [--only fib,loop,...] [--orb-ticks 3000] [--bp-ticks 20000]
5
- [--runs 5] [--out target/master_vs_simpler]
7
+ [--master DIR [--master-plum PATH]]
6
- [--only fib,loop,...]
7
8
 
8
- Run from the root of a simpler-language checkout. DIR is a checkout of master (cd59829 or
9
+ Run from the root of a simpler-language checkout; `--plum` defaults to target/release/plum.
10
+ By default only the branch runs: its default build, --no-fbip and --no-fusion. With
11
+ `--master DIR` (a checkout of master, cd59829 or later, with its compiler built;
9
- later) with its compiler built; `--master-plum` defaults to DIR/target/release/plum and
12
+ `--master-plum` defaults to DIR/target/release/plum) master runs too and the tables compare
10
- `--plum` to target/release/plum. Each compiler compiles with its own std: master's
13
+ the two. Each compiler compiles with its own std: master's programs from DIR, the branch's
11
- programs from DIR, the branch's from here.
14
+ from here.
12
15
 
13
16
  No program compiles unchanged on both branches (master needs `return` in a block body and
14
17
  rejects `fun f() = value`; the branch needs `= value` and has no `return`), so every
@@ -18,14 +21,17 @@ own game (master's examples/games/orbitrunner and balloonpop, the branch's
18
21
  examples/games/orb_run and kids/balloon_pop): this script copies the game without its
19
22
  `main` and tests and appends a headless `main` that steps it a fixed number of ticks with
20
23
  inputs that are a function of the seed and tick only. The branch's Orb Run is given
21
- master's restart rule (`ORB_BRANCH_AGAIN`), so the two play the same games.
24
+ master's restart rule (`ORB_BRANCH_AGAIN`), so the two play the same games; it is given it
25
+ without `--master` too, so the checksums stay comparable from run to run (at the default
26
+ ticks Orb Run prints checksum 871028980, Balloon Pop checksum 234038249 with 3975 pops).
27
+ `--orb-ticks` and `--bp-ticks` make a quick run (`--orb-ticks 300 --bp-ticks 1000 --runs 1`).
22
28
 
23
29
  For each program: `plum compile` --runs times on each branch (median ms, wasm bytes),
24
- `plum build` executables (master; the branch's default, --no-fbip and --no-fusion), then
30
+ `plum build` executables (master, when given; the branch's default, --no-fbip and
25
- --runs rounds, each running every executable once as a fresh process in a rotated order.
31
+ --no-fusion), then --runs rounds, each running every executable once as a fresh process in
26
- Every program prints `ms <in-program ms, from io.nowMicros> checksum ...`; the run fails if
32
+ a rotated order. Every program prints `ms <in-program ms, from io.nowMicros> checksum ...`;
27
- the branch's three builds disagree on the rest of the line, or if master's line differs from
33
+ the run fails if the branch's three builds disagree on the rest of the line, or if master's
28
- the branch's.
34
+ line differs from the branch's.
29
35
  """
30
36
  import argparse
31
37
  import json
@@ -224,18 +230,22 @@ fun main(io: Io) =
224
230
  '''
225
231
 
226
232
 
227
- def write_games(master, out):
233
+ def write_games(master, out, orb_ticks, bp_ticks, only):
234
+ """Writes the game drivers into `out` (master's only when `master` is given; only those
228
- """Writes the four game drivers into `out` and returns their (name, master, branch) paths."""
235
+ in `only` when it is given) and returns their (name, master, branch) paths."""
229
236
  games = [
230
- ("orb_run", master + "/examples/games/orbitrunner/OrbitRunner.plum", "fun main(io: Io) -> OrbitRunner",
237
+ ("orb_run", "/examples/games/orbitrunner/OrbitRunner.plum", "fun main(io: Io) -> OrbitRunner",
231
- ORB_MASTER, "examples/games/orb_run.plum", "fun main(io: Io) -> Game<State, Msg>", ORB_BRANCH, ORB_TICKS, ORB_SEEDS),
238
+ ORB_MASTER, "examples/games/orb_run.plum", "fun main(io: Io) -> Game<State, Msg>", ORB_BRANCH, orb_ticks, ORB_SEEDS),
232
- ("balloon_pop", master + "/examples/games/balloonpop/BalloonPop.plum", "fun main(io: Io) -> BalloonPop",
239
+ ("balloon_pop", "/examples/games/balloonpop/BalloonPop.plum", "fun main(io: Io) -> BalloonPop",
233
- BP_MASTER, "examples/games/kids/balloon_pop.plum", "fun main(io: Io) -> Game<State, Msg>", BP_BRANCH, BP_TICKS, BP_SEEDS),
240
+ BP_MASTER, "examples/games/kids/balloon_pop.plum", "fun main(io: Io) -> Game<State, Msg>", BP_BRANCH, bp_ticks, BP_SEEDS),
234
241
  ]
235
242
  progs = []
236
243
  for name, msrc, msig, mdrv, bsrc, bsig, bdrv, ticks, seeds in games:
244
+ if only and name not in only:
245
+ continue
237
246
  mp, bp = f"{out}/{name}_master.plum", f"{out}/{name}_branch.plum"
238
- for path, src, sig, drv in ((mp, msrc, msig, mdrv), (bp, bsrc, bsig, bdrv)):
247
+ sides = [(bp, bsrc, bsig, bdrv)] + ([(mp, master + msrc, msig, mdrv)] if master else [])
248
+ for path, src, sig, drv in sides:
239
249
  body = drv.replace("SEEDS", seeds).replace("TICKS", str(ticks))
240
250
  game = strip_main(src, sig)
241
251
  if path == bp and name == "orb_run":
@@ -252,29 +262,41 @@ def fmt(x):
252
262
 
253
263
  def main():
254
264
  ap = argparse.ArgumentParser()
255
- ap.add_argument("--master", required=True)
265
+ ap.add_argument("--master", help="a built checkout of master, to compare against")
256
266
  ap.add_argument("--master-plum")
257
267
  ap.add_argument("--plum", default="target/release/plum")
258
268
  ap.add_argument("--runs", type=int, default=5)
259
269
  ap.add_argument("--out", default="target/master_vs_simpler")
260
270
  ap.add_argument("--only")
271
+ ap.add_argument("--orb-ticks", type=int, default=ORB_TICKS)
272
+ ap.add_argument("--bp-ticks", type=int, default=BP_TICKS)
261
273
  a = ap.parse_args()
274
+ if a.master_plum and not a.master:
275
+ sys.exit("--master-plum needs --master")
276
+ broot = os.getcwd()
262
- mroot, broot = os.path.abspath(a.master), os.getcwd()
277
+ mroot = os.path.abspath(a.master) if a.master else None
263
- mplum = os.path.abspath(a.master_plum) if a.master_plum else mroot + "/target/release/plum"
278
+ mplum = (os.path.abspath(a.master_plum) if a.master_plum else mroot + "/target/release/plum") if mroot else None
264
279
  bplum = os.path.abspath(a.plum)
280
+ for what, path in [("--plum", bplum)] + ([("--master-plum", mplum)] if mroot else []):
281
+ if not os.path.isfile(path):
282
+ sys.exit(f"{what}: no compiler at {path}")
283
+ if mroot and not os.path.isdir(os.path.join(mroot, "std")):
284
+ sys.exit(f"--master: {mroot} is not a checkout (no std folder)")
265
285
  out = os.path.abspath(a.out)
266
286
  os.makedirs(out, exist_ok=True)
287
+ keep = a.only.split(",") if a.only else None
267
- progs = [(n, f"{HERE}/master/{n}.plum", f"{HERE}/branch/{n}.plum") for n in MICRO] + write_games(mroot, out)
288
+ progs = [(n, f"{HERE}/master/{n}.plum", f"{HERE}/branch/{n}.plum") for n in MICRO] + write_games(mroot, out, a.orb_ticks, a.bp_ticks, keep)
268
- if a.only:
289
+ if keep:
269
- keep = a.only.split(",")
270
290
  progs = [p for p in progs if p[0] in keep]
271
- vers = [("master", mplum, mroot, []), ("branch", bplum, broot, []),
291
+ vers = ([("master", mplum, mroot, [])] if mroot else []) + [
272
- ("branch --no-fbip", bplum, broot, ["--no-fbip"]), ("branch --no-fusion", bplum, broot, ["--no-fusion"])]
292
+ ("branch", bplum, broot, []), ("branch --no-fbip", bplum, broot, ["--no-fbip"]),
293
+ ("branch --no-fusion", bplum, broot, ["--no-fusion"])]
273
294
  names = [v[0] for v in vers]
295
+ compiled = [v for v in vers if v[0] in ("master", "branch")]
274
296
  res = {}
275
297
  for name, msrc, bsrc in progs:
276
298
  r = res.setdefault(name, {"compile": {}, "size": {}, "run": {}, "line": {}})
277
- for v, plum, root, _ in vers[:2]:
299
+ for v, plum, root, _ in compiled:
278
300
  src, wasm = (msrc if v == "master" else bsrc), f"{out}/{name}.{v}.wasm"
279
301
  ts = []
280
302
  for _ in range(a.runs):
@@ -297,33 +319,43 @@ def main():
297
319
  r["line"].setdefault(v, set()).add(m.group(2).strip())
298
320
  print(f"{name}: round {k + 1} done", file=sys.stderr)
299
321
  lines = {v: sorted(r["line"][v]) for v in names}
322
+ branches = [v for v in names if v != "master"]
300
- if len({tuple(lines[v]) for v in names[1:]}) != 1 or len(lines["branch"]) != 1:
323
+ if len({tuple(lines[v]) for v in branches}) != 1 or len(lines["branch"]) != 1:
301
324
  sys.exit(f"{name}: the branch's builds disagree: {lines}")
302
- if lines["master"] != lines["branch"]:
325
+ if mroot and lines["master"] != lines["branch"]:
303
326
  sys.exit(f"{name}: master and the branch print different results: {lines}")
304
327
  r["line"] = lines
305
328
  json.dump(res, open(f"{out}/results.json", "w"), indent=1)
306
329
  med = statistics.median
330
+ ratio = " branch / master |" if mroot else ""
307
- print("| program | master | branch | branch --no-fbip | branch --no-fusion | branch / master |")
331
+ print("| program | " + " | ".join(names) + " |" + ratio)
308
- print("|---|---|---|---|---|---|")
332
+ print("|---|" + "---|" * (len(names) + (1 if mroot else 0)))
309
333
  for name, *_ in progs:
310
334
  r = res[name]
311
335
  cells = [f"{fmt(med(r['run'][v]))} ({fmt(min(r['run'][v]))}-{fmt(max(r['run'][v]))})" for v in names]
312
- print(f"| {name} | " + " | ".join(cells) + f" | {med(r['run']['branch']) / med(r['run']['master']):.2f}x |")
336
+ tail = f" {med(r['run']['branch']) / max(med(r['run']['master']), 1e-9):.2f}x |" if mroot else ""
337
+ print(f"| {name} | " + " | ".join(cells) + " |" + tail)
313
338
  print()
339
+ if mroot:
314
- print("| program | master compile ms | branch compile ms | ratio | master wasm bytes | branch wasm bytes | ratio |")
340
+ print("| program | master compile ms | branch compile ms | ratio | master wasm bytes | branch wasm bytes | ratio |")
315
- print("|---|---|---|---|---|---|---|")
341
+ print("|---|---|---|---|---|---|---|")
316
- for name, *_ in progs:
342
+ for name, *_ in progs:
317
- r = res[name]
343
+ r = res[name]
318
- mc, bc = med(r["compile"]["master"]), med(r["compile"]["branch"])
344
+ mc, bc = med(r["compile"]["master"]), med(r["compile"]["branch"])
319
- ms, bs = r["size"]["master"], r["size"]["branch"]
345
+ ms, bs = r["size"]["master"], r["size"]["branch"]
320
- print(f"| {name} | {fmt(mc)} | {fmt(bc)} | {bc / mc:.2f}x | {ms} | {bs} | {bs / ms:.2f}x |")
346
+ print(f"| {name} | {fmt(mc)} | {fmt(bc)} | {bc / mc:.2f}x | {ms} | {bs} | {bs / ms:.2f}x |")
321
- print()
347
+ print()
322
- print("| program | master prints | branch prints (all three builds) |")
348
+ print("| program | master prints | branch prints (all three builds) |")
323
- print("|---|---|---|")
349
+ print("|---|---|---|")
324
- for name, *_ in progs:
350
+ for name, *_ in progs:
325
- r = res[name]
351
+ r = res[name]
326
- print(f"| {name} | {'; '.join(r['line']['master'])} | {'; '.join(r['line']['branch'])} |")
352
+ print(f"| {name} | {'; '.join(r['line']['master'])} | {'; '.join(r['line']['branch'])} |")
353
+ else:
354
+ print("| program | compile ms | wasm bytes | prints (all three builds) |")
355
+ print("|---|---|---|---|")
356
+ for name, *_ in progs:
357
+ r = res[name]
358
+ print(f"| {name} | {fmt(med(r['compile']['branch']))} | {r['size']['branch']} | {'; '.join(r['line']['branch'])} |")
327
359
 
328
360
 
329
361
  if __name__ == "__main__":