aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Molina <miguel@erizocosmi.co>2018-08-10 10:37:26 +0200
committerMiguel Molina <miguel@erizocosmi.co>2018-08-10 10:37:26 +0200
commitb944bc45af20b7362786f014fba1bbd72ba7fc76 (patch)
treebf7ed5785f98599988ccd595e8361e6b8e61c98c
parent56c5e91b158bc4569b38bfd5d27d4b4be5e06a27 (diff)
downloadgo-git-b944bc45af20b7362786f014fba1bbd72ba7fc76.tar.gz
git: add benchmark for iterating repository objects
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
-rw-r--r--repository_test.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
index b78fbb7..e34627e 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -1688,3 +1688,59 @@ func (s *RepositorySuite) TestBrokenMultipleShallowFetch(c *C) {
})
c.Assert(err, IsNil)
}
+
+func BenchmarkObjects(b *testing.B) {
+ if err := fixtures.Init(); err != nil {
+ b.Fatal(err)
+ }
+
+ defer func() {
+ if err := fixtures.Clean(); err != nil {
+ b.Fatal(err)
+ }
+ }()
+
+ for _, f := range fixtures.ByTag("packfile") {
+ if f.DotGitHash == plumbing.ZeroHash {
+ continue
+ }
+
+ b.Run(f.URL, func(b *testing.B) {
+ fs := f.DotGit()
+ storer, err := filesystem.NewStorage(fs)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ worktree, err := fs.Chroot(filepath.Dir(fs.Root()))
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ repo, err := Open(storer, worktree)
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ for i := 0; i < b.N; i++ {
+ iter, err := repo.Objects()
+ if err != nil {
+ b.Fatal(err)
+ }
+
+ for {
+ _, err := iter.Next()
+ if err == io.EOF {
+ break
+ }
+
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+
+ iter.Close()
+ }
+ })
+ }
+}