Debian Codegraph @

bench/Makefile

raw
1 # Makefile for the bench/ module (comparison benchmarks + trace replay).
2 #
3 # Targets:
4 # bench - synthetic comparison benchmarks (SIEVE vs LRU vs ARC)
5 # trace - trace replay benchmarks + miss-ratio + GC-pressure tests
6 # test - compile-check (bench module has no Test* without -tags=trace)
7 # race - compile-check under -race
8 # clean - remove generated result files
9 #
10 # Build tags cleanly separate the two worlds — no -bench=FILTER expression
11 # is used anywhere:
12 # bench_test.go has //go:build !trace (synth only)
13 # trace.go has //go:build trace (parser library)
14 # trace_test.go has //go:build trace (parser smoke tests)
15 # replay_test.go has //go:build trace (replay + miss-ratio + GC)
16 #
17 # So `go test -bench=.` picks up exactly one of the two sets depending on
18 # whether -tags=trace is passed.
19 #
20 # Trace data expected in DATADIR (default: ../data/). Fetch with:
21 # ./fetch-traces.sh
22
23 SHELL := /bin/bash
24 GOTEST := go test
25 COUNT := 3
26 TRACE_COUNT := 1
27 TIMEOUT := 60m
28 DATADIR := ../data
29
30 # Core counts for the scaling sweep; override with SWEEP_PROCS="1 4 16".
31 SWEEP_PROCS := 1 2 4 8 16 32
32 SWEEP_BENCH := Get_Parallel|Mixed_Parallel
33
34 OUT_BENCH := results/synthetic.txt
35 OUT_TRACE := results/trace.txt
36 OUT_SWEEP := results/sweep.txt
37
38 .DEFAULT_GOAL := help
39 .PHONY: help all bench trace sweep compare test race clean check-traces
40
41 help:
42 @echo "bench/Makefile — comparison benchmarks and trace replay"
43 @echo ""
44 @echo "Targets:"
45 @echo " bench - synthetic comparison benchmarks (SIEVE vs LRU vs ARC)"
46 @echo " -> $(OUT_BENCH)"
47 @echo " trace - trace replay + miss-ratio + GC-pressure (needs $(DATADIR))"
48 @echo " -> $(OUT_TRACE)"
49 @echo " sweep - core-scaling sweep: $(SWEEP_BENCH) at GOMAXPROCS=$(SWEEP_PROCS)"
50 @echo " -> $(OUT_SWEEP)"
51 @echo " compare - benchstat OLD=<file> NEW=<file> (defaults to $(OUT_BENCH))"
52 @echo " test - go test (compile-check; no Test* without -tags=trace)"
53 @echo " race - go test -race (compile-check under race detector)"
54 @echo " all - bench + trace"
55 @echo " clean - remove generated result files"
56 @echo " help - this message (default)"
57
58 all: bench trace
59
60 # stamp writes a metadata header so every results file is self-describing.
61 # Lines start with '#' — benchstat and the table generator skip them.
62 define stamp
63 ( echo "# date: $$(date -u +%Y-%m-%dT%H:%M:%SZ)"; \
64 echo "# host: $$(uname -srm)"; \
65 echo "# cpu: $$(sysctl -n machdep.cpu.brand_string 2>/dev/null || grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | sed 's/^ //')"; \
66 echo "# ncpu: $$(sysctl -n hw.ncpu 2>/dev/null || nproc)"; \
67 echo "# go: $$(go version)"; \
68 echo "# commit: $$(git rev-parse --short HEAD)$$(git diff --quiet 2>/dev/null || echo -dirty)" ) > $(1)
69 endef
70
71 bench:
72 @mkdir -p results
73 $(call stamp,$(OUT_BENCH))
74 $(GOTEST) -bench=. -benchmem -count=$(COUNT) -timeout=$(TIMEOUT) | tee -a $(OUT_BENCH)
75
76 trace: check-traces
77 @mkdir -p results
78 $(call stamp,$(OUT_TRACE))
79 $(GOTEST) -tags=trace -bench=. -benchmem -count=$(TRACE_COUNT) -v -timeout=$(TIMEOUT) | tee -a $(OUT_TRACE)
80
81 # Core-scaling sweep: substantiates the "scales with cores" claim by
82 # running the parallel benchmarks at increasing GOMAXPROCS.
83 sweep:
84 @mkdir -p results
85 $(call stamp,$(OUT_SWEEP))
86 @for p in $(SWEEP_PROCS); do \
87 echo "=== GOMAXPROCS=$$p ===" | tee -a $(OUT_SWEEP); \
88 GOMAXPROCS=$$p $(GOTEST) -bench='$(SWEEP_BENCH)' -benchmem -count=$(COUNT) -timeout=$(TIMEOUT) | tee -a $(OUT_SWEEP); \
89 done
90
91 # Compare two benchmark result files (needs golang.org/x/perf/cmd/benchstat).
92 OLD ?= $(OUT_BENCH)
93 NEW ?=
94 compare:
95 @if [ -z "$(NEW)" ]; then echo "usage: make compare OLD=<file> NEW=<file>"; exit 1; fi
96 benchstat $(OLD) $(NEW)
97
98 test:
99 $(GOTEST) -count=1
100
101 race:
102 $(GOTEST) -race -count=1
103
104 check-traces:
105 @if [ ! -d $(DATADIR) ]; then \
106 echo "ERROR: trace data missing at $(DATADIR)."; \
107 echo "Run ./fetch-traces.sh to download it."; \
108 exit 1; \
109 fi
110
111 clean:
112 rm -f $(OUT_BENCH) $(OUT_TRACE) $(OUT_SWEEP)