This repository has been archived by the owner on Apr 12, 2019. It is now read-only.
forked from gogs/git-module
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faster implementation of GetCommitsInfo
- Loading branch information
1 parent
f0a094c
commit ab9e103
Showing
4 changed files
with
198 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ _testmain.go | |
*.prof | ||
|
||
coverage.out | ||
|
||
benchmark_repos/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// 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 ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const benchmarkReposDir = "benchmark_repos/" | ||
|
||
func setupGitRepo(url string, name string) (string, error) { | ||
repoDir := filepath.Join(benchmarkReposDir, name) | ||
if _, err := os.Stat(repoDir); err == nil { | ||
return repoDir, nil | ||
} | ||
return repoDir, Clone(url, repoDir, CloneRepoOptions{ | ||
Mirror: false, | ||
Bare: false, | ||
Quiet: true, | ||
Timeout: 5 * time.Minute, | ||
}) | ||
} | ||
|
||
func BenchmarkEntries_GetCommitsInfo(b *testing.B) { | ||
benchmarks := []struct { | ||
url string | ||
name string | ||
}{ | ||
{url: "https://github.com/go-gitea/gitea.git", name: "gitea"}, | ||
{url: "https://github.com/ethantkoenig/manyfiles.git", name: "manyfiles"}, | ||
{url: "https://github.com/moby/moby.git", name: "moby"}, | ||
{url: "https://github.com/golang/go.git", name: "go"}, | ||
{url: "https://github.com/torvalds/linux.git", name: "linux"}, | ||
} | ||
for _, benchmark := range benchmarks { | ||
var commit *Commit | ||
var entries Entries | ||
if repoPath, err := setupGitRepo(benchmark.url, benchmark.name); err != nil { | ||
panic(err) | ||
} else if repo, err := OpenRepository(repoPath); err != nil { | ||
panic(err) | ||
} else if commit, err = repo.GetBranchCommit("master"); err != nil { | ||
panic(err) | ||
} else if entries, err = commit.Tree.ListEntries(); err != nil { | ||
panic(err) | ||
} | ||
entries.Sort() | ||
b.Run(benchmark.name, func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
_, err := entries.GetCommitsInfo(commit, "") | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
}) | ||
} | ||
} |