Skip to content

Commit 4a25347

Browse files
committed
Added commit-iteration test
1 parent 8c1a87d commit 4a25347

File tree

1 file changed

+56
-40
lines changed

1 file changed

+56
-40
lines changed

Diff for: test/git/test_performance.py

+56-40
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,62 @@
77
from test.testlib import *
88
from git import *
99
from time import time
10+
import sys
1011

1112
class TestPerformance(TestBase):
1213

13-
def _query_commit_info(self, c):
14-
c.author
15-
c.authored_date
16-
c.author_tz_offset
17-
c.committer
18-
c.committed_date
19-
c.committer_tz_offset
20-
c.message
21-
c.parents
22-
23-
def test_iteration(self):
24-
num_objs = 0
25-
num_commits = 0
26-
27-
# find the first commit containing the given path - always do a full
28-
# iteration ( restricted to the path in question ), but in fact it should
29-
# return quite a lot of commits, we just take one and hence abort the operation
30-
31-
st = time()
32-
for c in self.rorepo.iter_commits('0.1.6'):
33-
num_commits += 1
34-
self._query_commit_info(c)
35-
for obj in c.tree.traverse():
36-
obj.size
37-
num_objs += 1
38-
# END for each object
39-
# END for each commit
40-
elapsed_time = time() - st
41-
print "Traversed %i Trees and a total of %i unchached objects in %s [s] ( %f objs/s )" % (num_commits, num_objs, elapsed_time, num_objs/elapsed_time)
42-
43-
def test_commit_traversal(self):
44-
num_commits = 0
45-
46-
st = time()
47-
for c in self.rorepo.commit('0.1.6').traverse(branch_first=False):
48-
num_commits += 1
49-
self._query_commit_info(c)
50-
# END for each traversed commit
51-
elapsed_time = time() - st
52-
print "Traversed %i Commits in %s [s] ( %f commits/s )" % (num_commits, elapsed_time, num_commits/elapsed_time)
14+
# ref with about 100 commits in its history
15+
ref_100 = '0.1.6'
16+
17+
def _query_commit_info(self, c):
18+
c.author
19+
c.authored_date
20+
c.author_tz_offset
21+
c.committer
22+
c.committed_date
23+
c.committer_tz_offset
24+
c.message
25+
c.parents
26+
27+
def test_iteration(self):
28+
no = 0
29+
nc = 0
30+
31+
# find the first commit containing the given path - always do a full
32+
# iteration ( restricted to the path in question ), but in fact it should
33+
# return quite a lot of commits, we just take one and hence abort the operation
34+
35+
st = time()
36+
for c in self.rorepo.iter_commits(self.ref_100):
37+
nc += 1
38+
self._query_commit_info(c)
39+
for obj in c.tree.traverse():
40+
obj.size
41+
no += 1
42+
# END for each object
43+
# END for each commit
44+
elapsed_time = time() - st
45+
print >> sys.stderr, "Traversed %i Trees and a total of %i unchached objects in %s [s] ( %f objs/s )" % (nc, no, elapsed_time, no/elapsed_time)
46+
47+
def test_commit_traversal(self):
48+
# bound to cat-file parsing performance
49+
nc = 0
50+
st = time()
51+
for c in self.rorepo.commit(self.ref_100).traverse(branch_first=False):
52+
nc += 1
53+
self._query_commit_info(c)
54+
# END for each traversed commit
55+
elapsed_time = time() - st
56+
print >> sys.stderr, "Traversed %i Commits in %s [s] ( %f commits/s )" % (nc, elapsed_time, nc/elapsed_time)
57+
58+
def test_commit_iteration(self):
59+
# bound to stream parsing performance
60+
nc = 0
61+
st = time()
62+
for c in Commit.iter_items(self.rorepo, self.ref_100):
63+
nc += 1
64+
self._query_commit_info(c)
65+
# END for each traversed commit
66+
elapsed_time = time() - st
67+
print >> sys.stderr, "Iterated %i Commits in %s [s] ( %f commits/s )" % (nc, elapsed_time, nc/elapsed_time)
68+

0 commit comments

Comments
 (0)