5
5
Tries serializing an inventory to basic_io repeatedly.
9
14
from timeit import Timer
10
15
from tempfile import TemporaryFile, NamedTemporaryFile
12
17
from bzrlib.branch import Branch
13
18
from bzrlib.xml5 import serializer_v5
14
from bzrlib.basicio import write_inventory, BasicWriter
17
inv = b.get_inventory(b.last_revision())
19
from bzrlib.basicio import write_inventory, BasicWriter, BasicReader, \
21
from bzrlib.inventory import Inventory, InventoryEntry, InventoryFile, ROOT_ID
23
## b = Branch.open('.')
24
## inv = b.get_inventory(b.last_revision())
29
inv.add(InventoryFile('%08d-id' % i, '%08d-file' % i, ROOT_ID))
32
inv = make_inventory()
18
34
bio_tmp = NamedTemporaryFile()
19
35
xml_tmp = NamedTemporaryFile()
37
53
t = Timer(function_name + '()',
38
54
'from __main__ import ' + function_name)
39
55
times = t.repeat(1, ntimes)
40
57
size = tmp_file.tell()
41
print 'wrote inventory to %10s %d times, each %d bytes, total %dkB' \
58
print 'wrote inventory to %10s %5d times, each %6d bytes, total %6dkB' \
42
59
% (function_name, ntimes, size, (size * ntimes)>>10),
43
60
each = (min(times)/ntimes*1000)
44
print 'in %.3fms each' % each
61
print 'in %.1fms each' % each
47
xml_each = run_benchmark('xml_test', xml_tmp)
48
bio_each = run_benchmark('bio_test', bio_tmp)
65
import hotshot, hotshot.stats
66
prof_f = NamedTemporaryFile()
67
prof = hotshot.Profile(prof_f.name)
70
stats = hotshot.stats.load(prof_f.name)
72
stats.sort_stats('time')
73
## XXX: Might like to write to stderr or the trace file instead but
74
## print_stats seems hardcoded to stdout
50
print 'so bio is %.1f%% faster' % (100 * ((xml_each / bio_each) - 1))
77
if '-p' in sys.argv[1:]:
80
bio_each = run_benchmark('bio_test', bio_tmp)
81
xml_each = run_benchmark('xml_test', xml_tmp)
82
print 'so bio is %.1f%% faster' % (100 * ((xml_each / bio_each) - 1))
52
84
# make sure it was a fair comparison
53
assert 'cElementTree' in sys.modules
85
# assert 'cElementTree' in sys.modules