test/genbench.sh: the bench's program written by sh and awk, the same bytes; the tests need no Python
| @@ -53,7 +53,7 @@ | ||
| 53 | 53 | # the compiler's speed, on a generated program of about 350,000 lines, |
| 54 | 54 | # the best of three runs; fails below 400,000 lines a second |
| 55 | 55 | bench: raz | build |
| 56 | - python3 test/genbench.py 12000 > build/Bench.raz | |
| 56 | + sh test/genbench.sh 12000 > build/Bench.raz | |
| 57 | 57 | @lines=$$(wc -l < build/Bench.raz); best=0; \ |
| 58 | 58 | for i in 1 2 3; do \ |
| 59 | 59 | start=$$(date +%s%N); ./raz build/Bench.raz || exit 1; end=$$(date +%s%N); \ |
| @@ -72,7 +72,7 @@ | ||
| 72 | 72 | |
| 73 | 73 | Both take `PREFIX=/usr/local` (or another place) instead of `~/.local`. |
| 74 | 74 | |
| 75 | -The tests need a shell and Python 3; the editor checks run if vim or | |
| 75 | +The tests need only a shell; the editor checks run if vim or | |
| 76 | 76 | emacs is installed. |
| 77 | 77 | |
| 78 | 78 | make check # every example and test, against what it should give |
| @@ -1,61 +0,0 @@ | ||
| 1 | -"""Writes a large raz program to standard output, for timing the | |
| 2 | -compiler: n procedures of loops, conditions, records, slices and calls, | |
| 3 | -each calling the one before, so that none is left out.""" | |
| 4 | -import sys | |
| 5 | - | |
| 6 | -n = int(sys.argv[1]) | |
| 7 | -print("""module Bench; | |
| 8 | -import Out; | |
| 9 | - | |
| 10 | -type | |
| 11 | - Pair = record x, y: INT; end; | |
| 12 | - Shape = variant circle(r: INT); rect(w, h: INT); dot; end; | |
| 13 | - | |
| 14 | -var | |
| 15 | - g: [16]INT; | |
| 16 | - data: [64]INT; | |
| 17 | -""") | |
| 18 | -print("""proc p0(a, b: INT; _s: []INT): INT; | |
| 19 | -begin | |
| 20 | - return a + b; | |
| 21 | -end; | |
| 22 | -""") | |
| 23 | -for i in range(1, n + 1): | |
| 24 | - print(f"""(* procedure {i} *) | |
| 25 | -proc p{i}(a, b: INT; s: []INT): INT; | |
| 26 | -var i, t: INT; r: Pair; sh: Shape; | |
| 27 | -begin | |
| 28 | - t := 0; | |
| 29 | - for i := 0 to LEN(s) - 1 do | |
| 30 | - if s[i] > a then | |
| 31 | - t := t + s[i] * b; | |
| 32 | - elsif s[i] = b then | |
| 33 | - t := t - 1; | |
| 34 | - else | |
| 35 | - t := t xor i; | |
| 36 | - end; | |
| 37 | - end; | |
| 38 | - r.x := t; | |
| 39 | - r.y := a + b * {i}; | |
| 40 | - while r.x > 100 do | |
| 41 | - r.x := r.x div 2; | |
| 42 | - end; | |
| 43 | - sh := rect(r.x, r.y); | |
| 44 | - match sh of | |
| 45 | - | circle(c): t := t + c; | |
| 46 | - | rect(w, h): t := t + w * h; | |
| 47 | - | dot: t := t - 1; | |
| 48 | - end; | |
| 49 | - g[a & 15] := r.x + r.y; | |
| 50 | - return p{i - 1}(t & 1023, b, s[0..LEN(s) div 2]) + r.x; | |
| 51 | -end; | |
| 52 | -""") | |
| 53 | -print(f"""proc main*; | |
| 54 | -var i: INT; | |
| 55 | -begin | |
| 56 | - for i := 0 to 63 do data[i] := i; end; | |
| 57 | - Out.int(p{n}(1, 2, data[0..4])); | |
| 58 | - Out.ln; | |
| 59 | -end; | |
| 60 | - | |
| 61 | -end Bench.""") |
| @@ -0,0 +1,69 @@ | ||
| 1 | +#!/bin/sh | |
| 2 | +# Writes a large raz program to standard output, for timing the | |
| 3 | +# compiler: n procedures of loops, conditions, records, slices and | |
| 4 | +# calls, each calling the one before, so that none is left out. | |
| 5 | +# sh test/genbench.sh n > build/Bench.raz | |
| 6 | +n=$1 | |
| 7 | +cat <<'END' | |
| 8 | +module Bench; | |
| 9 | +import Out; | |
| 10 | + | |
| 11 | +type | |
| 12 | + Pair = record x, y: INT; end; | |
| 13 | + Shape = variant circle(r: INT); rect(w, h: INT); dot; end; | |
| 14 | + | |
| 15 | +var | |
| 16 | + g: [16]INT; | |
| 17 | + data: [64]INT; | |
| 18 | + | |
| 19 | +proc p0(a, b: INT; _s: []INT): INT; | |
| 20 | +begin | |
| 21 | + return a + b; | |
| 22 | +end; | |
| 23 | + | |
| 24 | +END | |
| 25 | +# awk, not a loop of the shell, so that 12,000 procedures take a moment | |
| 26 | +awk -v n="$n" 'BEGIN { | |
| 27 | + for (i = 1; i <= n; i++) { | |
| 28 | + printf "(* procedure %d *)\n", i | |
| 29 | + printf "proc p%d(a, b: INT; s: []INT): INT;\n", i | |
| 30 | + print "var i, t: INT; r: Pair; sh: Shape;" | |
| 31 | + print "begin" | |
| 32 | + print " t := 0;" | |
| 33 | + print " for i := 0 to LEN(s) - 1 do" | |
| 34 | + print " if s[i] > a then" | |
| 35 | + print " t := t + s[i] * b;" | |
| 36 | + print " elsif s[i] = b then" | |
| 37 | + print " t := t - 1;" | |
| 38 | + print " else" | |
| 39 | + print " t := t xor i;" | |
| 40 | + print " end;" | |
| 41 | + print " end;" | |
| 42 | + print " r.x := t;" | |
| 43 | + printf " r.y := a + b * %d;\n", i | |
| 44 | + print " while r.x > 100 do" | |
| 45 | + print " r.x := r.x div 2;" | |
| 46 | + print " end;" | |
| 47 | + print " sh := rect(r.x, r.y);" | |
| 48 | + print " match sh of" | |
| 49 | + print " | circle(c): t := t + c;" | |
| 50 | + print " | rect(w, h): t := t + w * h;" | |
| 51 | + print " | dot: t := t - 1;" | |
| 52 | + print " end;" | |
| 53 | + print " g[a & 15] := r.x + r.y;" | |
| 54 | + printf " return p%d(t & 1023, b, s[0..LEN(s) div 2]) + r.x;\n", i - 1 | |
| 55 | + print "end;" | |
| 56 | + print "" | |
| 57 | + } | |
| 58 | +}' | |
| 59 | +cat <<END | |
| 60 | +proc main*; | |
| 61 | +var i: INT; | |
| 62 | +begin | |
| 63 | + for i := 0 to 63 do data[i] := i; end; | |
| 64 | + Out.int(p$n(1, 2, data[0..4])); | |
| 65 | + Out.ln; | |
| 66 | +end; | |
| 67 | + | |
| 68 | +end Bench. | |
| 69 | +END |