1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/bin/bash
# plain float loop against the same loop lifted by o3. the program is
# tests/programs/fbench.zc: 'a' is plain, 'b' is o3, and the digits are repetitions.
# the slope between 1 repetition and N drops startup and compile time, so
# this does not bootstrap the compiler. each kernel is poly() of 20000,
# and (int) of one call is 59997.
cd "$(dirname "$0")/../.."
CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
make -s build/core/genome.bin || exit 1
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
$CC -O2 -w -DJTYPE=int src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o "$T/zy" || exit 1
vms=("$T/zy"); names=("interp")
$CC -O2 -w src/micro/micro.c src/micro/port_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -Isrc/micro -o "$T/zym" && { vms+=("$T/zym"); names+=("micro"); }
if command -v llvm-config >/dev/null; then
$CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o "$T/zyl" $(llvm-config --ldflags --libs) \
&& { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static src/core/core.c src/core/io_linux.c -Isrc/core -Ibuild/core/map --embed-dir=build/core -o "$T/zyj" \
&& { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64"); }
fi
src=$(cat tests/programs/fbench.zc)
# milliseconds per call of kernel $2 (a or b) on vm $1
per() {
python3 - "$1" "$2" "$src" << 'PY'
import sys, time, subprocess
vm, which, src = sys.argv[1], sys.argv[2], sys.argv[3].encode()
def once(arg):
t0 = time.perf_counter()
p = subprocess.run(vm.split(), input=src + b"`" + arg.encode(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
return time.perf_counter() - t0, p.returncode, p.stdout
def best(arg):
b, out = 1e9, b""
for _ in range(3):
d, r, o = once(arg)
if r == 0 and d < b:
b, out = d, o
return b, out
one, _ = best(which + "1")
n = 4
while True:
many, out = best("%s%d" % (which, n))
if many - one > 0.8 or n >= 1024:
break
n *= 4
print("%.3f" % ((many - one) / (n - 1) * 1000))
print(out.decode().strip(), file=sys.stderr)
PY
}
printf "%-10s %12s %12s %8s\n" backend "plain ms" "o3 ms" speedup
for i in "${!vms[@]}"; do
p=$(per "${vms[$i]}" a)
o=$(per "${vms[$i]}" b)
printf "%-10s %12s %12s %8s\n" "${names[$i]}" "$p" "$o" "$(python3 -c "print('%.2fx' % ($p / $o) if $o else 'n/a')")"
done
|