Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit fba9a81

Browse files
committed
Add bench task
1 parent f0a094c commit fba9a81

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ lint:
3535
test:
3636
for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;
3737

38+
.PHONY: bench
39+
bench:
40+
go test -run=XXXXXX -benchtime=10s -bench=. || exit 1
41+
3842
.PHONY: build
3943
build:
4044
go build .

tree_entry_test.go

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)