From 2ec2433121fc2e85260bfb55751eb6beef60c025 Mon Sep 17 00:00:00 2001 From: Will Roden Date: Tue, 29 Dec 2020 18:05:51 -0600 Subject: [PATCH] expand the cache key to include bench args --- cmd/benchdiff/internal/benchdiff.go | 12 +++++++++++- go.mod | 1 + go.sum | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/benchdiff/internal/benchdiff.go b/cmd/benchdiff/internal/benchdiff.go index 617849e..13f4305 100644 --- a/cmd/benchdiff/internal/benchdiff.go +++ b/cmd/benchdiff/internal/benchdiff.go @@ -2,6 +2,7 @@ package internal import ( "bytes" + "encoding/base64" "encoding/json" "fmt" "io" @@ -11,6 +12,7 @@ import ( "strings" "github.com/willabides/benchdiff/pkg/benchstatter" + "golang.org/x/crypto/sha3" "golang.org/x/perf/benchstat" ) @@ -59,6 +61,14 @@ func (c *Benchdiff) baseRefRunner() *refRunner { } } +func (c *Benchdiff) cacheKey() string { + var b []byte + b = append(b, []byte(c.BenchCmd)...) + b = append(b, []byte(c.BenchArgs)...) + sum := sha3.Sum224(b) + return base64.RawURLEncoding.EncodeToString(sum[:]) +} + func (c *Benchdiff) runBenchmarks() (result *runBenchmarksResults, err error) { result = new(runBenchmarksResults) worktreeFilename := filepath.Join(c.ResultsDir, "benchdiff-worktree.out") @@ -90,7 +100,7 @@ func (c *Benchdiff) runBenchmarks() (result *runBenchmarksResults, err error) { return nil, err } - baseFilename := fmt.Sprintf("benchdiff-%s.out", baseSHA) + baseFilename := fmt.Sprintf("benchdiff-%s-%s.out", baseSHA, c.cacheKey()) baseFilename = filepath.Join(c.ResultsDir, baseFilename) result.headSHA = headSHA result.baseSHA = baseSHA diff --git a/go.mod b/go.mod index 3e16758..47b223f 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.15 require ( github.com/alecthomas/kong v0.2.12 github.com/stretchr/testify v1.5.1 + golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 golang.org/x/perf v0.0.0-20201207232921-bdcc6220ee90 ) diff --git a/go.sum b/go.sum index 34dd601..4419d43 100644 --- a/go.sum +++ b/go.sum @@ -25,6 +25,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=