Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/gitaly/linguist/language_stats_test.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/gitaly/linguist/language_stats_test.go b/internal/gitaly/linguist/language_stats_test.go
index 69a2c3b4f..a2a0d8779 100644
--- a/internal/gitaly/linguist/language_stats_test.go
+++ b/internal/gitaly/linguist/language_stats_test.go
@@ -252,3 +252,58 @@ 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) {
+ languages := []string{
+ "Ruby",
+ "Javascript",
+ "C++",
+ "Golang",
+ "HTML",
+ "CSS",
+ "SQL",
+ "Assembly",
+ "Elixir",
+ "C#",
+ "Kotlin",
+ "Zig",
+ }
+
+ stats := newLanguageStats()
+ lenLang := len(languages)
+
+ ctx := testhelper.Context(b)
+ cfg := testcfg.Build(b)
+ repoProto, _ := gittest.CreateRepository(b, ctx, cfg, gittest.CreateRepositoryConfig{
+ SkipCreationViaService: true,
+ })
+
+ repo := localrepo.NewTestRepo(b, cfg, repoProto)
+
+ rand.Seed(time.Now().UnixNano())
+
+ for i := 0; i < 3_000_000; i++ {
+ stats.add(
+ fmt.Sprintf("file_%010d", i),
+ languages[rand.Intn(lenLang-1)],
+ uint64(rand.Int()),
+ )
+ }
+
+ require.NoError(b, stats.save(repo, "1337C0DE"))
+
+ b.Run("totals", func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ _, _ = initLanguageStats(repo)
+ _ = stats.Totals
+ }
+ })
+
+ b.Run("allCounts", func(b *testing.B) {
+ for i := 0; i < b.N; i++ {
+ _, err := initLanguageStats(repo)
+ require.NoError(b, err)
+ _ = stats.allCounts()
+ }
+ })
+}