Skip to content

Commit 30f49d9

Browse files
committed
Revise docstrings/comments in performance tests
1 parent bffc537 commit 30f49d9

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

‎test/performance/test_commit.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# test_performance.py
21
# Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
32
#
43
# This module is part of GitPython and is released under
54
# the BSD License: https://opensource.org/license/bsd-3-clause/
5+
6+
"""Performance tests for commits (iteration, traversal, and serialization)."""
7+
68
from io import BytesIO
79
from time import time
810
import sys
@@ -19,7 +21,7 @@ def tearDown(self):
1921

2022
gc.collect()
2123

22-
# ref with about 100 commits in its history
24+
# ref with about 100 commits in its history.
2325
ref_100 = "0.1.6"
2426

2527
def _query_commit_info(self, c):
@@ -36,9 +38,9 @@ def test_iteration(self):
3638
no = 0
3739
nc = 0
3840

39-
# find the first commit containing the given path - always do a full
40-
# iteration ( restricted to the path in question ), but in fact it should
41-
# return quite a lot of commits, we just take one and hence abort the operation
41+
# Find the first commit containing the given path. Always do a full iteration
42+
# (restricted to the path in question). This should return quite a lot of
43+
# commits. We just take one and hence abort the operation.
4244

4345
st = time()
4446
for c in self.rorepo.iter_commits(self.ref_100):
@@ -57,7 +59,7 @@ def test_iteration(self):
5759
)
5860

5961
def test_commit_traversal(self):
60-
# bound to cat-file parsing performance
62+
# Bound to cat-file parsing performance.
6163
nc = 0
6264
st = time()
6365
for c in self.gitrorepo.commit().traverse(branch_first=False):
@@ -71,7 +73,7 @@ def test_commit_traversal(self):
7173
)
7274

7375
def test_commit_iteration(self):
74-
# bound to stream parsing performance
76+
# Bound to stream parsing performance.
7577
nc = 0
7678
st = time()
7779
for c in Commit.iter_items(self.gitrorepo, self.gitrorepo.head):
@@ -89,8 +91,8 @@ def test_commit_serialization(self):
8991

9092
rwrepo = self.gitrwrepo
9193
make_object = rwrepo.odb.store
92-
# direct serialization - deserialization can be tested afterwards
93-
# serialization is probably limited on IO
94+
# Direct serialization - deserialization can be tested afterwards.
95+
# Serialization is probably limited on IO.
9496
hc = rwrepo.commit(rwrepo.head)
9597

9698
nc = 5000

‎test/performance/test_odb.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Performance tests for object store"""
1+
"""Performance tests for object store."""
2+
23
import sys
34
from time import time
45

@@ -24,7 +25,7 @@ def test_random_access(self):
2425
results[0].append(elapsed)
2526

2627
# GET TREES
27-
# walk all trees of all commits
28+
# Walk all trees of all commits.
2829
st = time()
2930
blobs_per_commit = []
3031
nt = 0
@@ -35,7 +36,7 @@ def test_random_access(self):
3536
nt += 1
3637
if item.type == "blob":
3738
blobs.append(item)
38-
# direct access for speed
39+
# Direct access for speed.
3940
# END while trees are there for walking
4041
blobs_per_commit.append(blobs)
4142
# END for each commit
@@ -75,7 +76,7 @@ def test_random_access(self):
7576
results[2].append(elapsed)
7677
# END for each repo type
7778

78-
# final results
79+
# Final results.
7980
for test_name, a, b in results:
8081
print(
8182
"%s: %f s vs %f s, pure is %f times slower" % (test_name, a, b, b / a),

‎test/performance/test_streams.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
"""Performance data streaming performance"""
1+
"""Performance tests for data streaming."""
2+
23
import os
34
import subprocess
45
import sys
@@ -15,13 +16,13 @@
1516

1617

1718
class TestObjDBPerformance(TestBigRepoR):
18-
large_data_size_bytes = 1000 * 1000 * 10 # some MiB should do it
19-
moderate_data_size_bytes = 1000 * 1000 * 1 # just 1 MiB
19+
large_data_size_bytes = 1000 * 1000 * 10 # Some MiB should do it.
20+
moderate_data_size_bytes = 1000 * 1000 * 1 # Just 1 MiB.
2021

2122
@with_rw_repo("HEAD", bare=True)
2223
def test_large_data_streaming(self, rwrepo):
23-
# TODO: This part overlaps with the same file in gitdb.test.performance.test_stream
24-
# It should be shared if possible
24+
# TODO: This part overlaps with the same file in gitdb.test.performance.test_stream.
25+
# It should be shared if possible.
2526
ldb = LooseObjectDB(osp.join(rwrepo.git_dir, "objects"))
2627

2728
for randomize in range(2):
@@ -32,7 +33,7 @@ def test_large_data_streaming(self, rwrepo):
3233
elapsed = time() - st
3334
print("Done (in %f s)" % elapsed, file=sys.stderr)
3435

35-
# writing - due to the compression it will seem faster than it is
36+
# Writing - due to the compression it will seem faster than it is.
3637
st = time()
3738
binsha = ldb.store(IStream("blob", size, stream)).binsha
3839
elapsed_add = time() - st
@@ -45,7 +46,7 @@ def test_large_data_streaming(self, rwrepo):
4546
msg %= (size_kib, fsize_kib, desc, elapsed_add, size_kib / elapsed_add)
4647
print(msg, file=sys.stderr)
4748

48-
# reading all at once
49+
# Reading all at once.
4950
st = time()
5051
ostream = ldb.stream(binsha)
5152
shadata = ostream.read()
@@ -57,7 +58,7 @@ def test_large_data_streaming(self, rwrepo):
5758
msg %= (size_kib, desc, elapsed_readall, size_kib / elapsed_readall)
5859
print(msg, file=sys.stderr)
5960

60-
# reading in chunks of 1 MiB
61+
# Reading in chunks of 1 MiB.
6162
cs = 512 * 1000
6263
chunks = []
6364
st = time()
@@ -86,7 +87,7 @@ def test_large_data_streaming(self, rwrepo):
8687
file=sys.stderr,
8788
)
8889

89-
# del db file so git has something to do
90+
# del db file so git has something to do.
9091
ostream = None
9192
import gc
9293

@@ -95,34 +96,34 @@ def test_large_data_streaming(self, rwrepo):
9596

9697
# VS. CGIT
9798
##########
98-
# CGIT ! Can using the cgit programs be faster ?
99+
# CGIT! Can using the cgit programs be faster?
99100
proc = rwrepo.git.hash_object("-w", "--stdin", as_process=True, istream=subprocess.PIPE)
100101

101-
# write file - pump everything in at once to be a fast as possible
102-
data = stream.getvalue() # cache it
102+
# Write file - pump everything in at once to be a fast as possible.
103+
data = stream.getvalue() # Cache it.
103104
st = time()
104105
proc.stdin.write(data)
105106
proc.stdin.close()
106107
gitsha = proc.stdout.read().strip()
107108
proc.wait()
108109
gelapsed_add = time() - st
109110
del data
110-
assert gitsha == bin_to_hex(binsha) # we do it the same way, right ?
111+
assert gitsha == bin_to_hex(binsha) # We do it the same way, right?
111112

112-
# as its the same sha, we reuse our path
113+
# As it's the same sha, we reuse our path.
113114
fsize_kib = osp.getsize(db_file) / 1000
114115
msg = "Added %i KiB (filesize = %i KiB) of %s data to using git-hash-object in %f s ( %f Write KiB / s)"
115116
msg %= (size_kib, fsize_kib, desc, gelapsed_add, size_kib / gelapsed_add)
116117
print(msg, file=sys.stderr)
117118

118-
# compare ...
119+
# Compare.
119120
print(
120121
"Git-Python is %f %% faster than git when adding big %s files"
121122
% (100.0 - (elapsed_add / gelapsed_add) * 100, desc),
122123
file=sys.stderr,
123124
)
124125

125-
# read all
126+
# Read all.
126127
st = time()
127128
_hexsha, _typename, size, data = rwrepo.git.get_object_data(gitsha)
128129
gelapsed_readall = time() - st
@@ -132,14 +133,14 @@ def test_large_data_streaming(self, rwrepo):
132133
file=sys.stderr,
133134
)
134135

135-
# compare
136+
# Compare.
136137
print(
137138
"Git-Python is %f %% faster than git when reading big %sfiles"
138139
% (100.0 - (elapsed_readall / gelapsed_readall) * 100, desc),
139140
file=sys.stderr,
140141
)
141142

142-
# read chunks
143+
# Read chunks.
143144
st = time()
144145
_hexsha, _typename, size, stream = rwrepo.git.stream_object_data(gitsha)
145146
while True:
@@ -158,7 +159,7 @@ def test_large_data_streaming(self, rwrepo):
158159
)
159160
print(msg, file=sys.stderr)
160161

161-
# compare
162+
# Compare.
162163
print(
163164
"Git-Python is %f %% faster than git when reading big %s files in chunks"
164165
% (100.0 - (elapsed_readchunks / gelapsed_readchunks) * 100, desc),

0 commit comments

Comments
 (0)