diff options
Diffstat (limited to 'internal/gitaly/linguist/language_stats_test.go')
-rw-r--r-- | internal/gitaly/linguist/language_stats_test.go | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go index 69a2c3b4f..037d79bb8 100644 --- a/internal/gitaly/linguist/language_stats_test.go +++ b/internal/gitaly/linguist/language_stats_test.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" "testing" - "time" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v15/internal/git/gittest" @@ -252,3 +251,59 @@ func TestLanguageStats_save(t *testing.T) { require.Equal(t, s.Totals, loaded.Totals) require.Equal(t, s.ByFile, loaded.ByFile) } + +func BenchmarkLanguageStats(b *testing.B) { + ctx := testhelper.Context(b) + cfg := testcfg.Build(b) + repoProto, _ := gittest.CreateRepository(b, ctx, cfg, gittest.CreateRepositoryConfig{ + SkipCreationViaService: true, + }) + + repo := localrepo.NewTestRepo(b, cfg, repoProto) + + { + languages := []string{ + "Ruby", + "Javascript", + "C++", + "Golang", + "HTML", + "CSS", + "SQL", + "Assembly", + "Elixir", + "C#", + "Kotlin", + "Zig", + } + lenLang := len(languages) + stats := newLanguageStats() + rnd := rand.New(rand.NewSource(0x1337C0DE)) + + for i := 0; i < 3_000_000; i++ { + stats.add( + fmt.Sprintf("file_%010d", i), + languages[rnd.Intn(lenLang-1)], + uint64(rnd.Int()), + ) + } + + require.NoError(b, stats.save(repo, "1337C0DE")) + } + + b.Run("totals", func(b *testing.B) { + for i := 0; i < b.N; i++ { + stats, err := initLanguageStats(repo) + require.NoError(b, err) + _ = stats.Totals + } + }) + + b.Run("allCounts", func(b *testing.B) { + for i := 0; i < b.N; i++ { + stats, err := initLanguageStats(repo) + require.NoError(b, err) + _ = stats.allCounts() + } + }) +} |