From 3102dad5faf9b21d36f1e58748b62515ef1ee194 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Thu, 16 Feb 2023 16:49:37 -0500 Subject: gopls/internal/regtest/bench: move benchmarks into separate files For discoverability, and in preparation for adding more benchmarks, move benchmarks into separate files organized by operation. Also rename some benchmark functions to match their LSP operation. No other changes. Change-Id: Ic8743c4a5fef517084b08204d3c8d032c6e14b44 Reviewed-on: https://go-review.googlesource.com/c/tools/+/468878 gopls-CI: kokoro Reviewed-by: Alan Donovan Run-TryBot: Robert Findley TryBot-Result: Gopher Robot --- gopls/internal/regtest/bench/definition_test.go | 22 ++++++ .../internal/regtest/bench/editor_features_test.go | 83 ---------------------- gopls/internal/regtest/bench/hover_test.go | 23 ++++++ .../internal/regtest/bench/implementations_test.go | 21 ++++++ gopls/internal/regtest/bench/references_test.go | 22 ++++++ gopls/internal/regtest/bench/rename_test.go | 25 +++++++ 6 files changed, 113 insertions(+), 83 deletions(-) create mode 100644 gopls/internal/regtest/bench/definition_test.go delete mode 100644 gopls/internal/regtest/bench/editor_features_test.go create mode 100644 gopls/internal/regtest/bench/hover_test.go create mode 100644 gopls/internal/regtest/bench/implementations_test.go create mode 100644 gopls/internal/regtest/bench/references_test.go create mode 100644 gopls/internal/regtest/bench/rename_test.go diff --git a/gopls/internal/regtest/bench/definition_test.go b/gopls/internal/regtest/bench/definition_test.go new file mode 100644 index 000000000..20b75de73 --- /dev/null +++ b/gopls/internal/regtest/bench/definition_test.go @@ -0,0 +1,22 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bench + +import "testing" + +func BenchmarkGoToDefinition(b *testing.B) { + env := sharedEnv(b) + + env.OpenFile("internal/imports/mod.go") + loc := env.RegexpSearch("internal/imports/mod.go", "ModuleJSON") + env.GoToDefinition(loc) + env.Await(env.DoneWithOpen()) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + env.GoToDefinition(loc) + } +} diff --git a/gopls/internal/regtest/bench/editor_features_test.go b/gopls/internal/regtest/bench/editor_features_test.go deleted file mode 100644 index f27132c45..000000000 --- a/gopls/internal/regtest/bench/editor_features_test.go +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2022 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package bench - -import ( - "fmt" - "testing" -) - -func BenchmarkGoToDefinition(b *testing.B) { - env := sharedEnv(b) - - env.OpenFile("internal/imports/mod.go") - loc := env.RegexpSearch("internal/imports/mod.go", "ModuleJSON") - env.GoToDefinition(loc) - env.Await(env.DoneWithOpen()) - - b.ResetTimer() - - for i := 0; i < b.N; i++ { - env.GoToDefinition(loc) - } -} - -func BenchmarkFindAllReferences(b *testing.B) { - env := sharedEnv(b) - - env.OpenFile("internal/imports/mod.go") - loc := env.RegexpSearch("internal/imports/mod.go", "gopathwalk") - env.References(loc) - env.Await(env.DoneWithOpen()) - - b.ResetTimer() - - for i := 0; i < b.N; i++ { - env.References(loc) - } -} - -func BenchmarkRename(b *testing.B) { - env := sharedEnv(b) - - env.OpenFile("internal/imports/mod.go") - env.Await(env.DoneWithOpen()) - - b.ResetTimer() - - for i := 1; i < b.N; i++ { - loc := env.RegexpSearch("internal/imports/mod.go", "gopathwalk") - newName := fmt.Sprintf("%s%d", "gopathwalk", i) - env.Rename(loc, newName) - } -} - -func BenchmarkFindAllImplementations(b *testing.B) { - env := sharedEnv(b) - - env.OpenFile("internal/imports/mod.go") - loc := env.RegexpSearch("internal/imports/mod.go", "initAllMods") - env.Await(env.DoneWithOpen()) - - b.ResetTimer() - - for i := 0; i < b.N; i++ { - env.Implementations(loc) - } -} - -func BenchmarkHover(b *testing.B) { - env := sharedEnv(b) - - env.OpenFile("internal/imports/mod.go") - loc := env.RegexpSearch("internal/imports/mod.go", "bytes") - env.Await(env.DoneWithOpen()) - - b.ResetTimer() - - for i := 0; i < b.N; i++ { - env.Hover(loc) - } -} diff --git a/gopls/internal/regtest/bench/hover_test.go b/gopls/internal/regtest/bench/hover_test.go new file mode 100644 index 000000000..78fdc930a --- /dev/null +++ b/gopls/internal/regtest/bench/hover_test.go @@ -0,0 +1,23 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bench + +import ( + "testing" +) + +func BenchmarkHover(b *testing.B) { + env := sharedEnv(b) + + env.OpenFile("internal/imports/mod.go") + loc := env.RegexpSearch("internal/imports/mod.go", "bytes") + env.Await(env.DoneWithOpen()) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + env.Hover(loc) + } +} diff --git a/gopls/internal/regtest/bench/implementations_test.go b/gopls/internal/regtest/bench/implementations_test.go new file mode 100644 index 000000000..610a2d28c --- /dev/null +++ b/gopls/internal/regtest/bench/implementations_test.go @@ -0,0 +1,21 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bench + +import "testing" + +func BenchmarkFindAllImplementations(b *testing.B) { + env := sharedEnv(b) + + env.OpenFile("internal/imports/mod.go") + loc := env.RegexpSearch("internal/imports/mod.go", "initAllMods") + env.Await(env.DoneWithOpen()) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + env.Implementations(loc) + } +} diff --git a/gopls/internal/regtest/bench/references_test.go b/gopls/internal/regtest/bench/references_test.go new file mode 100644 index 000000000..e5f1f63df --- /dev/null +++ b/gopls/internal/regtest/bench/references_test.go @@ -0,0 +1,22 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bench + +import "testing" + +func BenchmarkReferences(b *testing.B) { + env := sharedEnv(b) + + env.OpenFile("internal/imports/mod.go") + loc := env.RegexpSearch("internal/imports/mod.go", "gopathwalk") + env.References(loc) + env.Await(env.DoneWithOpen()) + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + env.References(loc) + } +} diff --git a/gopls/internal/regtest/bench/rename_test.go b/gopls/internal/regtest/bench/rename_test.go new file mode 100644 index 000000000..e6db663a4 --- /dev/null +++ b/gopls/internal/regtest/bench/rename_test.go @@ -0,0 +1,25 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package bench + +import ( + "fmt" + "testing" +) + +func BenchmarkRename(b *testing.B) { + env := sharedEnv(b) + + env.OpenFile("internal/imports/mod.go") + env.Await(env.DoneWithOpen()) + + b.ResetTimer() + + for i := 1; i < b.N; i++ { + loc := env.RegexpSearch("internal/imports/mod.go", "gopathwalk") + newName := fmt.Sprintf("%s%d", "gopathwalk", i) + env.Rename(loc, newName) + } +} -- cgit v1.2.3