From f96277b9c0d4f6b43ec2e6e43cea2d0aa8dc1491 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:27:55 +0000 Subject: [PATCH] test/genbench.sh: the bench's program written by sh and awk, the same bytes; the tests need no Python --- diff --git a/Makefile b/Makefile index 07d26a4..51243a7 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ # the compiler's speed, on a generated program of about 350,000 lines, # the best of three runs; fails below 400,000 lines a second bench: raz | build - python3 test/genbench.py 12000 > build/Bench.raz + sh test/genbench.sh 12000 > build/Bench.raz @lines=$$(wc -l < build/Bench.raz); best=0; \ for i in 1 2 3; do \ start=$$(date +%s%N); ./raz build/Bench.raz || exit 1; end=$$(date +%s%N); \ diff --git a/README.md b/README.md index 758f5e1..0291db5 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ Both take `PREFIX=/usr/local` (or another place) instead of `~/.local`. -The tests need a shell and Python 3; the editor checks run if vim or +The tests need only a shell; the editor checks run if vim or emacs is installed. make check # every example and test, against what it should give diff --git a/test/genbench.py b/test/genbench.py deleted file mode 100644 index de43072..0000000 --- a/test/genbench.py +++ /dev/null @@ -1,61 +0,0 @@ -"""Writes a large raz program to standard output, for timing the -compiler: n procedures of loops, conditions, records, slices and calls, -each calling the one before, so that none is left out.""" -import sys - -n = int(sys.argv[1]) -print("""module Bench; -import Out; - -type - Pair = record x, y: INT; end; - Shape = variant circle(r: INT); rect(w, h: INT); dot; end; - -var - g: [16]INT; - data: [64]INT; -""") -print("""proc p0(a, b: INT; _s: []INT): INT; -begin - return a + b; -end; -""") -for i in range(1, n + 1): - print(f"""(* procedure {i} *) -proc p{i}(a, b: INT; s: []INT): INT; -var i, t: INT; r: Pair; sh: Shape; -begin - t := 0; - for i := 0 to LEN(s) - 1 do - if s[i] > a then - t := t + s[i] * b; - elsif s[i] = b then - t := t - 1; - else - t := t xor i; - end; - end; - r.x := t; - r.y := a + b * {i}; - while r.x > 100 do - r.x := r.x div 2; - end; - sh := rect(r.x, r.y); - match sh of - | circle(c): t := t + c; - | rect(w, h): t := t + w * h; - | dot: t := t - 1; - end; - g[a & 15] := r.x + r.y; - return p{i - 1}(t & 1023, b, s[0..LEN(s) div 2]) + r.x; -end; -""") -print(f"""proc main*; -var i: INT; -begin - for i := 0 to 63 do data[i] := i; end; - Out.int(p{n}(1, 2, data[0..4])); - Out.ln; -end; - -end Bench.""") diff --git a/test/genbench.sh b/test/genbench.sh new file mode 100644 index 0000000..d4e9102 --- /dev/null +++ b/test/genbench.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# Writes a large raz program to standard output, for timing the +# compiler: n procedures of loops, conditions, records, slices and +# calls, each calling the one before, so that none is left out. +# sh test/genbench.sh n > build/Bench.raz +n=$1 +cat <<'END' +module Bench; +import Out; + +type + Pair = record x, y: INT; end; + Shape = variant circle(r: INT); rect(w, h: INT); dot; end; + +var + g: [16]INT; + data: [64]INT; + +proc p0(a, b: INT; _s: []INT): INT; +begin + return a + b; +end; + +END +# awk, not a loop of the shell, so that 12,000 procedures take a moment +awk -v n="$n" 'BEGIN { + for (i = 1; i <= n; i++) { + printf "(* procedure %d *)\n", i + printf "proc p%d(a, b: INT; s: []INT): INT;\n", i + print "var i, t: INT; r: Pair; sh: Shape;" + print "begin" + print " t := 0;" + print " for i := 0 to LEN(s) - 1 do" + print " if s[i] > a then" + print " t := t + s[i] * b;" + print " elsif s[i] = b then" + print " t := t - 1;" + print " else" + print " t := t xor i;" + print " end;" + print " end;" + print " r.x := t;" + printf " r.y := a + b * %d;\n", i + print " while r.x > 100 do" + print " r.x := r.x div 2;" + print " end;" + print " sh := rect(r.x, r.y);" + print " match sh of" + print " | circle(c): t := t + c;" + print " | rect(w, h): t := t + w * h;" + print " | dot: t := t - 1;" + print " end;" + print " g[a & 15] := r.x + r.y;" + printf " return p%d(t & 1023, b, s[0..LEN(s) div 2]) + r.x;\n", i - 1 + print "end;" + print "" + } +}' +cat <