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

Commit 96af092

Browse files
committed
Create tree_entry_test.go
1 parent c84e4aa commit 96af092

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

tree_entry_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
15+
dir, err := ioutil.TempDir("", "gitea-bench")
16+
if err != nil {
17+
panic(err)
18+
}
19+
/* Manual method
20+
_, err = NewCommand("clone", url, dir).Run()
21+
if err != nil {
22+
log.Fatal(err)
23+
}
24+
*/
25+
err = Clone(url, dir, CloneRepoOptions{Mirror: false, Bare: false, Quiet: true})
26+
if err != nil {
27+
panic(err)
28+
}
29+
return dir
30+
}
31+
32+
func benchmarkGetCommitsInfo(url string, b *testing.B) {
33+
34+
// setup env
35+
repoPath := setupGitRepo(url)
36+
defer os.RemoveAll(repoPath)
37+
38+
repo, err := OpenRepository(repoPath)
39+
if err != nil {
40+
panic(err)
41+
}
42+
43+
commit, err := repo.GetBranchCommit("master")
44+
if err != nil {
45+
panic(err)
46+
}
47+
48+
entries, err := commit.Tree.ListEntries()
49+
if err != nil {
50+
panic(err)
51+
}
52+
entries.Sort()
53+
54+
// run the GetCommitsInfo function b.N times
55+
for n := 0; n < b.N; n++ {
56+
_, err = entries.GetCommitsInfo(commit, "")
57+
if err != nil {
58+
panic(err)
59+
}
60+
}
61+
}
62+
63+
64+
func BenchmarkGetCommitsInfoGitea(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/go-gitea/gitea.git", b) } //5k+ commits
65+
func BenchmarkGetCommitsInfoMoby(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/moby/moby.git", b) } //32k+ commits
66+
func BenchmarkGetCommitsInfoGo(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/golang/go.git", b) } //+32k commits

0 commit comments

Comments
 (0)