-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_test.go
57 lines (47 loc) · 833 Bytes
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package bench
import (
"log"
"os"
"testing"
"github.com/go-git/go-git/v5"
)
var (
localRepoDir string
repoURL = "https://github.com/go-git/go-git.git"
)
func TestMain(m *testing.M) {
var err error
localRepoDir, err = os.MkdirTemp("", "bench-test")
if err != nil {
log.Fatal(err)
}
_, err = git.PlainClone(localRepoDir, false, &git.CloneOptions{
URL: repoURL,
})
if err != nil {
log.Fatal(err)
}
code := m.Run()
os.Exit(code)
}
func BenchmarkPlainOpen(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := git.PlainOpen(localRepoDir)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkStatus(b *testing.B) {
r, err := git.PlainOpen(localRepoDir)
if err != nil {
b.Fatal(err)
}
wt, err := r.Worktree()
if err != nil {
b.Fatal(err)
}
for i := 0; i < b.N; i++ {
wt.Status()
}
}