|
| 1 | +// Copyright 2017 The Gitea Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a MIT-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package git |
| 6 | + |
| 7 | +import ( |
| 8 | + "io/ioutil" |
| 9 | + "os" |
| 10 | + "testing" |
| 11 | +) |
| 12 | + |
| 13 | +func setupGitRepo(url string) string { |
| 14 | + dir, err := ioutil.TempDir("", "gitea-bench") |
| 15 | + if err != nil { |
| 16 | + panic(err) |
| 17 | + } |
| 18 | + /* Manual method |
| 19 | + _, err = NewCommand("clone", url, dir).Run() |
| 20 | + if err != nil { |
| 21 | + log.Fatal(err) |
| 22 | + } |
| 23 | + */ |
| 24 | + err = Clone(url, dir, CloneRepoOptions{}) |
| 25 | + if err != nil { |
| 26 | + panic(err) |
| 27 | + } |
| 28 | + return dir |
| 29 | +} |
| 30 | + |
| 31 | +//TODO use https://blog.golang.org/subtests when removing support for Go1.6 |
| 32 | +func benchmarkGetCommitsInfo(url string, b *testing.B) { |
| 33 | + b.StopTimer() |
| 34 | + |
| 35 | + // setup env |
| 36 | + repoPath := setupGitRepo(url) |
| 37 | + defer os.RemoveAll(repoPath) |
| 38 | + |
| 39 | + repo, err := OpenRepository(repoPath) |
| 40 | + if err != nil { |
| 41 | + panic(err) |
| 42 | + } |
| 43 | + |
| 44 | + commit, err := repo.GetBranchCommit("master") |
| 45 | + if err != nil { |
| 46 | + panic(err) |
| 47 | + } |
| 48 | + |
| 49 | + entries, err := commit.Tree.ListEntries() |
| 50 | + if err != nil { |
| 51 | + panic(err) |
| 52 | + } |
| 53 | + entries.Sort() |
| 54 | + |
| 55 | + b.StartTimer() |
| 56 | + // run the GetCommitsInfo function b.N times |
| 57 | + for n := 0; n < b.N; n++ { |
| 58 | + _, err = entries.GetCommitsInfo(commit, "") |
| 59 | + if err != nil { |
| 60 | + panic(err) |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +func BenchmarkGetCommitsInfoGitea(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/go-gitea/gitea.git", b) } //5k+ commits |
| 67 | +func BenchmarkGetCommitsInfoMoby(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/moby/moby.git", b) } //32k+ commits |
| 68 | +func BenchmarkGetCommitsInfoGo(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/golang/go.git", b) } //32k+ commits |
| 69 | +func BenchmarkGetCommitsInfoLinux(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/torvalds/linux.git", b) } //677k+ commits |
| 70 | +func BenchmarkGetCommitsInfoManyFile(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/ethantkoenig/manyfiles", b) } |
0 commit comments