From 067dc391aa7e06dd0bb49bf6f6ea388eaa376997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20L=C3=B3pez?= Date: Tue, 23 Mar 2021 14:14:58 -0300 Subject: [PATCH] Add IdentifierSet.ToOrderedSlice and ToSlice benchmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be useful later on when implementing the performance improvements to compare how much we gain. Signed-off-by: Leandro López --- ast/util_test.go | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 ast/util_test.go diff --git a/ast/util_test.go b/ast/util_test.go new file mode 100644 index 0000000..17f6fdf --- /dev/null +++ b/ast/util_test.go @@ -0,0 +1,64 @@ +package ast + +import ( + "fmt" + "testing" +) + +func testIdentifiers(n int) Identifiers { + var is []Identifier + for i := 0; i < n; i++ { + is = append(is, Identifier(fmt.Sprintf("id-%06d", i))) + } + return Identifiers(is) +} + +var results []Identifier + +func BenchmarkToOrderedSlice(b *testing.B) { + tests := []Identifiers{ + testIdentifiers(1), + testIdentifiers(10), + testIdentifiers(100), + testIdentifiers(1000), + testIdentifiers(10000), + testIdentifiers(100000), + } + + for _, t := range tests { + is := IdentifierSet{} + is.AddIdentifiers(t) + + b.Run(fmt.Sprintf("%d unique identifiers", len(t)), func(b *testing.B) { + var r []Identifier + for i := 0; i < b.N; i++ { + r = is.ToOrderedSlice() + } + results = r + }) + } +} + +func BenchmarkToSlice(b *testing.B) { + tests := []Identifiers{ + testIdentifiers(1), + testIdentifiers(10), + testIdentifiers(100), + testIdentifiers(1000), + testIdentifiers(10000), + testIdentifiers(100000), + } + + for _, t := range tests { + is := IdentifierSet{} + is.AddIdentifiers(t) + + b.Run(fmt.Sprintf("%d unique identifiers", len(t)), func(b *testing.B) { + var r []Identifier + for i := 0; i < b.N; i++ { + r = is.ToSlice() + } + results = r + }) + } +}