From b944bc45af20b7362786f014fba1bbd72ba7fc76 Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Fri, 10 Aug 2018 10:37:26 +0200 Subject: git: add benchmark for iterating repository objects Signed-off-by: Miguel Molina --- repository_test.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'repository_test.go') 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() + } + }) + } +} -- cgit