|
| 1 | +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors |
| 2 | +# |
| 3 | +# This module is part of GitDB and is released under |
| 4 | +# the New BSD License: http://www.opensource.org/licenses/bsd-license.php |
1 | 5 | from packedodb_impl import TestPurePackedODBPerformanceBase
|
2 | 6 | from git.db.py.pack import PurePackedODB
|
3 | 7 |
|
| 8 | +from git.stream import NullStream |
| 9 | + |
| 10 | +from git.pack import PackEntity |
| 11 | + |
| 12 | +import os |
| 13 | +import sys |
| 14 | + |
| 15 | +from time import time |
| 16 | +from nose import SkipTest |
| 17 | + |
| 18 | + |
| 19 | +class CountedNullStream(NullStream): |
| 20 | + __slots__ = '_bw' |
| 21 | + def __init__(self): |
| 22 | + self._bw = 0 |
| 23 | + |
| 24 | + def bytes_written(self): |
| 25 | + return self._bw |
| 26 | + |
| 27 | + def write(self, d): |
| 28 | + self._bw += NullStream.write(self, d) |
| 29 | + |
| 30 | + |
4 | 31 | class TestPurePackedODB(TestPurePackedODBPerformanceBase):
|
5 | 32 | #{ Configuration
|
6 | 33 | PackedODBCls = PurePackedODB
|
7 | 34 | #} END configuration
|
| 35 | + |
| 36 | + def test_pack_writing(self): |
| 37 | + # see how fast we can write a pack from object streams. |
| 38 | + # This will not be fast, as we take time for decompressing the streams as well |
| 39 | + ostream = CountedNullStream() |
| 40 | + pdb = self.ropdb |
| 41 | + |
| 42 | + ni = 5000 |
| 43 | + count = 0 |
| 44 | + total_size = 0 |
| 45 | + st = time() |
| 46 | + objs = list() |
| 47 | + for sha in pdb.sha_iter(): |
| 48 | + count += 1 |
| 49 | + objs.append(pdb.stream(sha)) |
| 50 | + if count == ni: |
| 51 | + break |
| 52 | + #END gather objects for pack-writing |
| 53 | + elapsed = time() - st |
| 54 | + print >> sys.stderr, "PDB Streaming: Got %i streams by sha in in %f s ( %f streams/s )" % (ni, elapsed, ni / elapsed) |
| 55 | + |
| 56 | + st = time() |
| 57 | + PackEntity.write_pack(objs, ostream.write) |
| 58 | + elapsed = time() - st |
| 59 | + total_kb = ostream.bytes_written() / 1000 |
| 60 | + print >> sys.stderr, "PDB Streaming: Wrote pack of size %i kb in %f s (%f kb/s)" % (total_kb, elapsed, total_kb/elapsed) |
| 61 | + |
| 62 | + |
| 63 | + def test_stream_reading(self): |
| 64 | + raise SkipTest("This test was only used for --with-profile runs") |
| 65 | + pdb = self.ropdb |
| 66 | + |
| 67 | + # streaming only, meant for --with-profile runs |
| 68 | + ni = 5000 |
| 69 | + count = 0 |
| 70 | + pdb_stream = pdb.stream |
| 71 | + total_size = 0 |
| 72 | + st = time() |
| 73 | + for sha in pdb.sha_iter(): |
| 74 | + if count == ni: |
| 75 | + break |
| 76 | + stream = pdb_stream(sha) |
| 77 | + stream.read() |
| 78 | + total_size += stream.size |
| 79 | + count += 1 |
| 80 | + elapsed = time() - st |
| 81 | + total_kib = total_size / 1000 |
| 82 | + print >> sys.stderr, "PDB Streaming: Got %i streams by sha and read all bytes totallying %i KiB ( %f KiB / s ) in %f s ( %f streams/s )" % (ni, total_kib, total_kib/elapsed , elapsed, ni / elapsed) |
| 83 | + |
0 commit comments