github.com/kamalshkeir/kencoding@v0.0.2-0.20230409043843-44b609a0475a/Makefile (about) 1 .PHONY: test bench-simple clean update-golang-test fuzz fuzz-json 2 3 golang.version ?= 1.15.2 4 golang.tmp.root := /tmp/golang$(golang.version) 5 golang.tmp.json.root := $(golang.tmp.root)/go-go$(golang.version)/src/encoding/json 6 golang.test.files := $(wildcard json/golang_*_test.go) 7 benchstat := ${GOPATH}/bin/benchstat 8 go-fuzz := ${GOPATH}/bin/go-fuzz 9 go-fuzz-build := ${GOPATH}/bin/go-fuzz-build 10 go-fuzz-corpus := ${GOPATH}/src/github.com/dvyukov/go-fuzz-corpus 11 go-fuzz-dep := ${GOPATH}/src/github.com/dvyukov/go-fuzz/go-fuzz-dep 12 13 test: test-ascii test-json test-json-bugs test-json-1.17 test-proto test-iso8601 test-thrift test-purego 14 15 test-ascii: 16 go test -cover -race ./ascii 17 18 test-json: 19 go test -cover -race ./json 20 21 test-json-bugs: 22 go test -cover -race ./json/bugs/... 23 24 test-json-1.17: 25 go test -cover -race -tags go1.17 ./json 26 27 test-proto: 28 go test -cover -race ./proto 29 30 test-iso8601: 31 go test -cover -race ./iso8601 32 33 test-thrift: 34 go test -cover -race ./thrift 35 36 test-purego: 37 go test -race -tags purego ./... 38 39 $(benchstat): 40 GO111MODULE=off go get -u golang.org/x/perf/cmd/benchstat 41 42 # This compares segmentio/encoding/json to the standard golang encoding/json; 43 # for more in-depth benchmarks, see the `benchmarks` directory. 44 count ?= 5 45 bench-simple: $(benchstat) 46 @go test -v -run '^$$' -bench '(Marshal|Unmarshal)$$/codeResponse' -benchmem -cpu 1 -count $(count) ./json -package encoding/json | tee /tmp/encoding-json.txt 47 @go test -v -run '^$$' -bench '(Marshal|Unmarshal)$$/codeResponse' -benchmem -cpu 1 -count $(count) ./json | tee /tmp/segmentio-encoding-json.txt 48 benchstat /tmp/encoding-json.txt /tmp/segmentio-encoding-json.txt 49 50 bench-master: $(benchstat) 51 git stash 52 git checkout master 53 @go test -v -run '^$$' -bench /codeResponse -benchmem -benchtime 3s -cpu 1 ./json -count 8 | tee /tmp/segmentio-encoding-json-master.txt 54 git checkout - 55 git stash pop 56 @go test -v -run '^$$' -bench /codeResponse -benchmem -benchtime 3s -cpu 1 ./json -count 8 | tee /tmp/segmentio-encoding-json.txt 57 benchstat /tmp/segmentio-encoding-json-master.txt /tmp/segmentio-encoding-json.txt 58 59 update-golang-test: $(golang.test.files) 60 @echo "updated golang tests to $(golang.version)" 61 62 json/golang_%_test.go: $(golang.tmp.json.root)/%_test.go $(golang.tmp.json.root) 63 @echo "updating $@ with $<" 64 cp $< $@ 65 sed -i '' -E '/(import)?[ \t]*"internal\/.*".*/d' $@ 66 67 $(golang.tmp.json.root): $(golang.tmp.root) 68 curl -L "https://github.com/golang/go/archive/go${golang.version}.tar.gz" | tar xz -C "$</" 69 70 $(golang.tmp.root): 71 mkdir -p "$@" 72 73 $(go-fuzz): 74 GO111MODULE=off go install github.com/dvyukov/go-fuzz/go-fuzz 75 76 $(go-fuzz-build): 77 GO111MODULE=off go install github.com/dvyukov/go-fuzz/go-fuzz-build 78 79 $(go-fuzz-corpus): 80 GO111MODULE=off go get github.com/dvyukov/go-fuzz-corpus 81 82 $(go-fuzz-dep): 83 GO111MODULE=off go get github.com/dvyukov/go-fuzz/go-fuzz-dep 84 85 json/fuzz/corpus: $(go-fuzz-corpus) 86 cp -r $(go-fuzz-corpus)/json/corpus json/fuzz/corpus 87 88 json/fuzz/json-fuzz.zip: $(go-fuzz-build) $(go-fuzz-corpus) $(go-fuzz-dep) $(wildcard ./json/fuzz/corpus/*) 89 cd json/fuzz && GO111MODULE=off go-fuzz-build -o json-fuzz.zip 90 91 fuzz: fuzz-json 92 93 fuzz-json: $(go-fuzz) $(wildcard json/fuzz/*.go) json/fuzz/json-fuzz.zip 94 cd json/fuzz && GO111MODULE=off go-fuzz -bin json-fuzz.zip 95 96 clean: 97 rm -rf $(golang.tmp.root) json/fuzz/{crashers,corpus,suppressions,json-fuzz.zip} *json.txt