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:
authorToon Claes <toon@gitlab.com>2022-11-04 15:39:33 +0300
committerToon Claes <toon@gitlab.com>2022-11-04 16:18:52 +0300
commitd3f9abcf9a25b28fc5859f51d95663e7a62bef22 (patch)
treea1567b162e897b21b5d144b50bbe4db79e40e582
parentca607e6f265f39c2ae04aac46a9502a357fb738f (diff)
linguist: Add benchmark for languageStatstoon-linguist-cleanup
I was curious how much extra time it would take to calculate the FileCount: goos: linux goarch: amd64 pkg: gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/linguist cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz BenchmarkLanguageStats BenchmarkLanguageStats/totals BenchmarkLanguageStats/totals-8 1 4298347856 ns/op BenchmarkLanguageStats/allCounts BenchmarkLanguageStats/allCounts-8 1 6809731635 ns/op In this bench it takes about 4 seconds to load the stats from file, and we would calculate the FileCount it takes about 7 seconds in total.
-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()
+ }
+ })
+}