Skip to content

Commit c63db69

Browse files
committed
refact(elapsed): improve no div0 when time-elapsed too small
1 parent 7524f69 commit c63db69

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

gitdb/test/performance/test_pack.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def test_pack_random_access(self):
3232
# sha lookup
3333
st = time()
3434
sha_list = list(pdb.sha_iter())
35-
elapsed = time() - st
35+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
3636
ns = len(sha_list)
3737
print("PDB: looked up %i shas by index in %f s ( %f shas/s )" % (
38-
ns, elapsed, ns / (elapsed or 1)), file=sys.stderr)
38+
ns, elapsed, ns / elapsed), file=sys.stderr)
3939

4040
# sha lookup: best-case and worst case access
4141
pdb_pack_info = pdb._pack_info
@@ -44,13 +44,13 @@ def test_pack_random_access(self):
4444
for sha in sha_list:
4545
pdb_pack_info(sha)
4646
# END for each sha to look up
47-
elapsed = time() - st
47+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
4848

4949
# discard cache
5050
del(pdb._entities)
5151
pdb.entities()
5252
print("PDB: looked up %i sha in %i packs in %f s ( %f shas/s )" %
53-
(ns, len(pdb.entities()), elapsed, ns / (elapsed or 1)), file=sys.stderr)
53+
(ns, len(pdb.entities()), elapsed, ns / elapsed), file=sys.stderr)
5454
# END for each random mode
5555

5656
# query info and streams only
@@ -59,9 +59,9 @@ def test_pack_random_access(self):
5959
st = time()
6060
for sha in sha_list[:max_items]:
6161
pdb_fun(sha)
62-
elapsed = time() - st
62+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
6363
print("PDB: Obtained %i object %s by sha in %f s ( %f items/s )" %
64-
(max_items, pdb_fun.__name__.upper(), elapsed, max_items / (elapsed or 1)), file=sys.stderr)
64+
(max_items, pdb_fun.__name__.upper(), elapsed, max_items / elapsed), file=sys.stderr)
6565
# END for each function
6666

6767
# retrieve stream and read all
@@ -74,11 +74,11 @@ def test_pack_random_access(self):
7474
read_len = len(stream.read())
7575
assert read_len == stream.size
7676
total_size += stream.size
77-
elapsed = time() - st
77+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
7878
total_kib = total_size / 1000
7979
print("PDB: Obtained %i streams by sha and read all bytes "
8080
"totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" %
81-
(max_items, total_kib, total_kib / (elapsed or 1), elapsed, max_items / (elapsed or 1)), file=sys.stderr)
81+
(max_items, total_kib, total_kib / elapsed, elapsed, max_items / elapsed), file=sys.stderr)
8282

8383
def test_loose_correctness(self):
8484
"""based on the pack(s) of our packed object DB, we will just copy and verify all objects in the back
@@ -130,7 +130,7 @@ def test_correctness(self):
130130
# END ignore old indices
131131
# END for each index
132132
# END for each entity
133-
elapsed = time() - st
133+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
134134
print("PDB: verified %i objects (crc=%i) in %f s ( %f objects/s )" %
135-
(count, crc, elapsed, count / (elapsed or 1)), file=sys.stderr)
135+
(count, crc, elapsed, count / elapsed), file=sys.stderr)
136136
# END for each verify mode

gitdb/test/performance/test_pack_streaming.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def test_pack_writing(self):
4949
if count == ni:
5050
break
5151
# END gather objects for pack-writing
52-
elapsed = time() - st
52+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
5353
print("PDB Streaming: Got %i streams by sha in in %f s ( %f streams/s )" %
54-
(ni, elapsed, ni / (elapsed or 1)), file=sys.stderr)
54+
(ni, elapsed, ni / elapsed), file=sys.stderr)
5555

5656
st = time()
5757
## We are leaking files here, but we don't care...
@@ -60,10 +60,10 @@ def test_pack_writing(self):
6060
all_streams = [exs.enter_context(pdb.stream(sha))
6161
for sha in pdb.sha_iter()]
6262
PackEntity.write_pack((all_streams), ostream.write, object_count=ni)
63-
elapsed = time() - st
63+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
6464
total_kb = ostream.bytes_written() / 1000
6565
print(sys.stderr, "PDB Streaming: Wrote pack of size %i kb in %f s (%f kb/s)" %
66-
(total_kb, elapsed, total_kb / (elapsed or 1)), sys.stderr)
66+
(total_kb, elapsed, total_kb / elapsed), sys.stderr)
6767

6868
def test_stream_reading(self):
6969
# raise SkipTest()
@@ -82,8 +82,8 @@ def test_stream_reading(self):
8282
stream.read()
8383
total_size += stream.size
8484
count += 1
85-
elapsed = time() - st
85+
elapsed = max(time() - st, 0.001) # prevent zero divison errors on windows
8686
total_kib = total_size / 1000
8787
print(sys.stderr, "PDB Streaming: Got %i streams by sha and read all bytes "
8888
"totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" %
89-
(ni, total_kib, total_kib / (elapsed or 1), elapsed, ni / (elapsed or 1)), sys.stderr)
89+
(ni, total_kib, total_kib / elapsed, elapsed, ni / elapsed), sys.stderr)

0 commit comments

Comments
 (0)