diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 3d2383c..b3cff9e 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -1,61 +1,63 @@ +--- name: Benchmark -on: -- pull_request +"on": + - pull_request jobs: benchmark: strategy: matrix: ref: - - master - - ${{ github.sha }} + - master + - ${{ github.sha }} runs-on: ubuntu-latest steps: - - name: Steup Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Checkout - uses: actions/checkout@v2 - with: - ref: ${{ matrix.ref }} - - - name: Run Benchmarks - run: go test -v -run '^$' -bench '(Marshal|Unmarshal)$/codeResponse' -benchmem -benchtime 3s -cpu 1 -count 5 ./json | tee bench.txt - - - name: Upload Benchmarks - uses: actions/upload-artifact@v2 - with: - name: ${{ matrix.ref }} - path: bench.txt + - name: Steup Go + uses: actions/setup-go@v2 + with: + go-version: "1.21" + + - name: Checkout + uses: actions/checkout@v2 + with: + ref: ${{ matrix.ref }} + + - name: Run Benchmarks + # Without 6 iterations, benchstat will claim statistical insignificance. + run: go test -v -run '^$' -bench '(Marshal|Unmarshal)$/codeResponse' -benchmem -benchtime 3s -cpu 1 -count 6 ./json | tee bench.txt + + - name: Upload Benchmarks + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.ref }} + path: bench.txt benchstat: needs: [benchmark] runs-on: ubuntu-latest steps: - - name: Steup Go - uses: actions/setup-go@v2 - with: - go-version: 1.17 - - - name: Setup Benchstat - run: go install golang.org/x/perf/cmd/benchstat@latest - - - name: Download Benchmark Results - uses: actions/download-artifact@v2 - with: - path: . - - - name: Run Benchstat - run: benchstat ./master/bench.txt ./${{ github.sha }}/bench.txt | tee benchstat.txt - - - name: Upload Benchstat Results - uses: actions/upload-artifact@v2 - with: - name: benchstat - path: benchstat.txt + - name: Steup Go + uses: actions/setup-go@v2 + with: + go-version: "1.21" + + - name: Setup Benchstat + run: go install golang.org/x/perf/cmd/benchstat@latest + + - name: Download Benchmark Results + uses: actions/download-artifact@v2 + with: + path: . + + - name: Run Benchstat + run: benchstat ./master/bench.txt ./${{ github.sha }}/bench.txt | tee benchstat.txt + + - name: Upload Benchstat Results + uses: actions/upload-artifact@v2 + with: + name: benchstat + path: benchstat.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 16acc54..7e4bc41 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,30 +1,29 @@ +--- name: Test -on: -- pull_request +"on": + - pull_request jobs: test: strategy: matrix: go: - - 1.14 - - 1.15 - - 1.16 - - 1.17 + - "1.20" + - "1.21" runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Setup Go ${{ matrix.go }} - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go }} + - name: Setup Go ${{ matrix.go }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go }} - - name: Download Dependencies - run: go mod download + - name: Download Dependencies + run: go mod download - - name: Run Tests - run: make test + - name: Run Tests + run: make test diff --git a/Makefile b/Makefile index ffb1396..4640625 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: test bench-simple clean update-golang-test fuzz fuzz-json -golang.version ?= 1.15.2 +golang.version ?= 1.21 golang.tmp.root := /tmp/golang$(golang.version) golang.tmp.json.root := $(golang.tmp.root)/go-go$(golang.version)/src/encoding/json golang.test.files := $(wildcard json/golang_*_test.go) @@ -10,7 +10,7 @@ go-fuzz-build := ${GOPATH}/bin/go-fuzz-build go-fuzz-corpus := ${GOPATH}/src/github.com/dvyukov/go-fuzz-corpus go-fuzz-dep := ${GOPATH}/src/github.com/dvyukov/go-fuzz/go-fuzz-dep -test: test-ascii test-json test-json-bugs test-json-1.17 test-proto test-iso8601 test-thrift test-purego +test: test-ascii test-json test-json-bugs test-proto test-iso8601 test-thrift test-purego test-ascii: go test -cover -race ./ascii @@ -21,9 +21,6 @@ test-json: test-json-bugs: go test -race ./json/bugs/... -test-json-1.17: - go test -cover -race -tags go1.17 ./json - test-proto: go test -cover -race ./proto diff --git a/json/golang_bench_test.go b/json/golang_bench_test.go index 07cc378..04c9176 100644 --- a/json/golang_bench_test.go +++ b/json/golang_bench_test.go @@ -14,7 +14,7 @@ import ( "bytes" "compress/gzip" "fmt" - "io/ioutil" + "io" "os" "reflect" "runtime" @@ -51,7 +51,7 @@ func codeInit() { if err != nil { panic(err) } - data, err := ioutil.ReadAll(gz) + data, err := io.ReadAll(gz) if err != nil { panic(err) } @@ -88,7 +88,7 @@ func BenchmarkCodeEncoder(b *testing.B) { b.StartTimer() } b.RunParallel(func(pb *testing.PB) { - enc := NewEncoder(ioutil.Discard) + enc := NewEncoder(io.Discard) for pb.Next() { if err := enc.Encode(&codeStruct); err != nil { b.Fatal("Encode:", err) diff --git a/proto/fixtures/generate/main.go b/proto/fixtures/generate/main.go index 3016afd..0614934 100644 --- a/proto/fixtures/generate/main.go +++ b/proto/fixtures/generate/main.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "os" "github.com/golang/protobuf/proto" @@ -28,6 +27,6 @@ func main() { for _, test := range tests { b, _ := proto.Marshal(&test.value) - ioutil.WriteFile("protobuf/"+test.name, b, 0644) + os.WriteFile("protobuf/"+test.name, b, 0644) } } diff --git a/proto/proto_test.go b/proto/proto_test.go index fd7573a..d978aaf 100644 --- a/proto/proto_test.go +++ b/proto/proto_test.go @@ -3,8 +3,8 @@ package proto import ( "encoding/binary" "fmt" - "io/ioutil" "math" + "os" "reflect" "testing" ) @@ -366,7 +366,7 @@ func TestMarshalUnmarshal(t *testing.T) { } func loadProtobuf(t *testing.T, fileName string) RawMessage { - b, err := ioutil.ReadFile("fixtures/protobuf/" + fileName) + b, err := os.ReadFile("fixtures/protobuf/" + fileName) if err != nil { t.Fatal(err) } diff --git a/thrift/decode.go b/thrift/decode.go index 341d10a..4cc394b 100644 --- a/thrift/decode.go +++ b/thrift/decode.go @@ -5,7 +5,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "reflect" "sync/atomic" ) @@ -656,7 +655,7 @@ func skipBinary(r Reader) error { case *bufio.Reader: _, err = x.Discard(int(n)) default: - _, err = io.CopyN(ioutil.Discard, x, int64(n)) + _, err = io.CopyN(io.Discard, x, int64(n)) } return dontExpectEOF(err) }