Debian Codegraph @

internal/benchtest/Makefile

raw
1 # vim: ts=4 sw=4 ft=make
2
3 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
4 MAKEFILE_DIR := $(dir $(MAKEFILE_PATH))
5 PATH := $(MAKEFILE_DIR)/bin:$(PATH)
6
7 COUNT ?= 1 # Number of benchmark iterations (`-count` flag)
8 TIMEOUT ?= 4h # Benchmark timeout (`-timeout` flag)
9 BENCHTIME ?= 1s # Benchmark run time (`-benchtime` flag)
10
11 GO ?= go
12 GOBIN ?= $(MAKEFILE_DIR)/bin
13 GO_TEST_FLAGS ?= -timeout=$(TIMEOUT) -count=$(COUNT) -benchtime=$(BENCHTIME)
14 GO_TEST ?= $(GO) test $(GO_TEST_FLAGS)
15 TIMESTAMP := $(shell date +%s)
16 TEE ?= false # Tee benchmark results to a file
17
18 BENCHSTAT_PKG ?= golang.org/x/perf/cmd/benchstat@latest
19 BENCHCMP_PKG ?= golang.org/x/tools/cmd/benchcmp@latest
20
21 # By default, we exclude IndexNonASCII in the benchmark comparison since
22 # it distorts the overall delta since on amd64 and arm64 it is significantly
23 # faster than the naive approach.
24 BENCHSTAT_FILTER ?= -.name:/IndexNonASCII/
25 BENCHSTAT_CONFIDENCE ?= 0
26 BENCHSTAT_ARGS ?=
27 ifneq (,$(BENCHSTAT_CONFIDENCE))
28 BENCHSTAT_ARGS += -confidence=$(BENCHSTAT_CONFIDENCE)
29 endif
30 ifneq (,$(BENCHSTAT_FILTER))
31 BENCHSTAT_ARGS += -filter='$(BENCHSTAT_FILTER)'
32 endif
33
34 .PHONY: all
35 all: bench
36
37 # install benchstat tool
38 bin/benchstat:
39 @mkdir -p $(GOBIN); \
40 GOBIN=$(GOBIN) $(GO) install $(BENCHSTAT_PKG); \
41
42 # install benchcmp tool
43 bin/benchcmp:
44 @mkdir -p $(GOBIN); \
45 GOBIN=$(GOBIN) $(GO) install $(BENCHCMP_PKG); \
46
47 # Install benchstat and benchcmp
48 .PHONY: install-tools
49 install-tools: bin/benchstat bin/benchcmp
50
51 stdlib: GO_TEST_FLAGS += -stdlib
52 stdlib-case: GO_TEST_FLAGS += -stdlib-case
53
54 # Run benchmarks:
55 #
56 # bench: run strcase target
57 # strcase: strcase package
58 # stdlib: strings package
59 # stdlib-case: strings package and covert case
60 #
61 .PHONY: bench strcase stdlib stdlib-case
62 bench strcase stdlib stdlib-case:
63 @if $(TEE); then \
64 $(GO_TEST) -bench . | tee "$(@).$(TIMESTAMP).txt"; \
65 else \
66 $(GO_TEST) -bench .; \
67 fi;
68
69 .PHONY: benchstat
70 benchstat:
71 @benchstat $(BENCHSTAT_ARGS) stdlib.$(TIMESTAMP).txt strcase.$(TIMESTAMP).txt | \
72 tee result.$(TIMESTAMP).txt
73
74 # release creates the "release" benchmarks which compare the
75 # performance of strcase against the stdlib's strings package
76 #
77 # WARN: this is very very slow
78 #
79 # TODO: don't include IndexNonASCII in benchmarks since it distorts
80 # the overall delta (since on amd64 and arm64 it is significantly
81 # faster than the naive approach).
82 .PHONY: release
83 release: COUNT = 6
84 release: TEE = true
85 release: bin/benchcmp commit_hash git_diff
86 release: strcase # The following targets need to be ran sequentially
87 release: stdlib
88 release: benchstat
89
90 # Since the release target compares the results of the strcase and stdlib
91 # targets it cannot be ran in parallel.
92 .NOTPARALLEL: release
93
94 .PHONY: commit_hash
95 commit_hash:
96 @git rev-parse HEAD > commit.$(TIMESTAMP).txt
97
98 .PHONY: git_diff
99 git_diff:
100 @git diff --patch > patch.$(TIMESTAMP).patch
101
102 # test is a a no-op and is only here to make `checkmake` happy
103 .PHONY: test
104 test:
105 @$(GO) test
106
107 .PHONY: clean
108 clean:
109 @[[ ! -d $(GOBIN) ]] || rm -r $(GOBIN);
110 @$(GO) clean -i