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

Add some benchmark #54

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ lint:
test:
for PKG in $(PACKAGES); do go test -cover -coverprofile $$GOPATH/src/$$PKG/coverage.out $$PKG || exit 1; done;

.PHONY: bench
bench:
go test -run=XXXXXX -benchtime=10s -bench=. || exit 1

.PHONY: build
build:
go build .
67 changes: 67 additions & 0 deletions tree_entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package git

import (
"io/ioutil"
"os"
"testing"
)

func setupGitRepo(url string) (string, error) {
dir, err := ioutil.TempDir("", "gitea-bench")
if err != nil {
return "", err
}
err = Clone(url, dir, CloneRepoOptions{})
if err != nil {
return "", err
}
return dir, nil
}

//TODO use https://blog.golang.org/subtests when removing support for Go1.6
func benchmarkGetCommitsInfo(url string, b *testing.B) {
b.StopTimer()

// setup env
repoPath, err := setupGitRepo(url)
if err != nil {
b.Fatal(err)
}
defer os.RemoveAll(repoPath)

repo, err := OpenRepository(repoPath)
if err != nil {
b.Fatal(err)
}

commit, err := repo.GetBranchCommit("master")
if err != nil {
b.Fatal(err)
}

entries, err := commit.Tree.ListEntries()
if err != nil {
b.Fatal(err)
}
entries.Sort()

b.StartTimer()
// run the GetCommitsInfo function b.N times
for n := 0; n < b.N; n++ {
_, err = entries.GetCommitsInfo(commit, "")
if err != nil {
b.Fatal(err)
}
}
}


func BenchmarkGetCommitsInfoGitea(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/go-gitea/gitea.git", b) } //5k+ commits
func BenchmarkGetCommitsInfoMoby(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/moby/moby.git", b) } //32k+ commits
func BenchmarkGetCommitsInfoGo(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/golang/go.git", b) } //32k+ commits
func BenchmarkGetCommitsInfoLinux(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/torvalds/linux.git", b) } //677k+ commits
func BenchmarkGetCommitsInfoManyFile(b *testing.B) { benchmarkGetCommitsInfo("https://github.com/ethantkoenig/manyfiles", b) }