From 2ac40aec002b5588dbac3e6cd6a9970683852acd Mon Sep 17 00:00:00 2001 From: fujiwara Date: Tue, 17 Sep 2024 14:30:51 +0900 Subject: [PATCH] add benchmark goos: linux goarch: amd64 pkg: github.com/fujiwara/tfstate-lookup/tfstate cpu: AMD Ryzen 5 3400G with Radeon Vega Graphics BenchmarkLookupFile-8 3056 374179 ns/op 210225 B/op 2549 allocs/op PASS --- tfstate/lookup_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tfstate/lookup_test.go b/tfstate/lookup_test.go index 77a1c11..8ea1ef0 100644 --- a/tfstate/lookup_test.go +++ b/tfstate/lookup_test.go @@ -229,6 +229,25 @@ func TestLookupFileURL(t *testing.T) { testLookupState(t, state) } +func BenchmarkLookupFile(b *testing.B) { + f, err := os.Open("test/terraform.tfstate") + if err != nil { + b.Error(err) + } + state, err := tfstate.Read(context.Background(), f) + if err != nil { + b.Error(err) + } + for i := 0; i < b.N; i++ { + for _, ts := range TestSuitesOK { + _, err := state.Lookup(ts.Key) + if err != nil { + b.Error(err) + } + } + } +} + func TestLookupHTTPURL(t *testing.T) { h := http.FileServer(http.Dir(".")) ts := httptest.NewServer(h)