diff options
author | Toon Claes <toon@gitlab.com> | 2022-11-04 15:39:33 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-11-15 11:09:46 +0300 |
commit | fb5eac77cef4cb63f4928a06831c943858436e75 (patch) | |
tree | b303314a6bb55db859e1a8b76f2f6a6669821858 | |
parent | fc45c1c86b8c5c0419cf4b4f305c9d1bb2709031 (diff) |
linguist: Add benchmark for languageStatstoon-linguist-filecount
I was curious how much extra time it would take to calculate the
FileCount, so with this change we generate fake language stats with 3
million files of 12 random languages. We write these stats to file and
then measure how long it takes to load them. We compare the times with
and without getting the file count.
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, when
the FileCount is included it takes about 7 seconds in total.
-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() + } + }) +} |