/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/biobench.py

  • Committer: Vincent Ladeuil
  • Date: 2009-10-06 14:40:37 UTC
  • mto: (4728.1.2 integration)
  • mto: This revision was merged to the branch mainline in revision 4731.
  • Revision ID: v.ladeuil+lp@free.fr-20091006144037-o76rgosv9hj3td0y
Simplify mutable_tree.has_changes() and update call sites.

* bzrlib/workingtree.py:
(WorkingTree.merge_from_branch): Add a force parameter. Replace
the check_basis() call by the corresponding code, taken the new
'force' parameter into account.

* bzrlib/tests/test_status.py:
(TestStatus.make_multiple_pending_tree): Add force=True on
supplementary merges.

* bzrlib/tests/test_reconfigure.py:
(TestReconfigure): Add a test for pending merges.

* bzrlib/tests/test_msgeditor.py:
(MsgEditorTest.make_multiple_pending_tree): Add force=True on
supplementary merges.

* bzrlib/tests/blackbox/test_uncommit.py:
(TestUncommit.test_uncommit_octopus_merge): Add force=True on
supplementary merges.

* bzrlib/send.py:
(send): Use the simplified has_changes(). Fix typo in comment too.

* bzrlib/reconfigure.py:
(Reconfigure._check): Use the simplified has_changes().

* bzrlib/mutabletree.py:
(MutableTree.has_changes): Make the tree parameter optional but
retain it for tests. Add a pending merges check.

* bzrlib/merge.py:
(Merger.ensure_revision_trees, Merger.file_revisions,
Merger.check_basis, Merger.compare_basis): Deprecate.

* bzrlib/bundle/apply_bundle.py:
(merge_bundle): Replace the check_basis() call by the
corresponding code.

* bzrlib/builtins.py:
(cmd_remove_tree.run, cmd_push.run, cmd_merge.run): Use the
simplified has_changes().
(cmd_merge.run): Replace the check_basis call() by the corresponding
code (minus the alredy done has_changes() check).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
 
 
3
# (C) 2005 Canonical Ltd
 
4
 
 
5
"""Benchmark for basicio
 
6
 
 
7
Tries serializing an inventory to basic_io repeatedly.
 
8
"""
 
9
 
 
10
if True:
 
11
    import psyco
 
12
    psyco.full()
 
13
 
 
14
 
 
15
import sys
 
16
from timeit import Timer
 
17
from tempfile import TemporaryFile, NamedTemporaryFile
 
18
 
 
19
from bzrlib.branch import Branch
 
20
from bzrlib.xml5 import serializer_v5
 
21
from bzrlib.basicio import write_inventory, BasicWriter, \
 
22
        read_inventory
 
23
from bzrlib.inventory import Inventory, InventoryEntry, InventoryFile, ROOT_ID
 
24
 
 
25
## b = Branch.open('.')
 
26
## inv = b.get_inventory(b.last_revision())
 
27
 
 
28
nrepeats = 3
 
29
ntimes = 5
 
30
NFILES = 30000
 
31
 
 
32
def make_inventory():
 
33
    inv = Inventory()
 
34
    for i in range(NFILES):
 
35
        ie = InventoryFile('%08d-id' % i, '%08d-file' % i, ROOT_ID)
 
36
        ie.text_sha1='1212121212121212121212121212121212121212'
 
37
        ie.text_size=12312
 
38
        inv.add(ie)
 
39
    return inv
 
40
 
 
41
inv = make_inventory()
 
42
 
 
43
bio_tmp = NamedTemporaryFile()
 
44
xml_tmp = NamedTemporaryFile()
 
45
 
 
46
def bio_test():
 
47
    bio_tmp.seek(0)
 
48
    w = BasicWriter(bio_tmp)
 
49
    write_inventory(w, inv)
 
50
    bio_tmp.seek(0)
 
51
    new_inv = read_inventory(bio_tmp)
 
52
 
 
53
def xml_test():
 
54
    xml_tmp.seek(0)
 
55
    serializer_v5.write_inventory(inv, xml_tmp)
 
56
    xml_tmp.seek(0)
 
57
    new_inv = serializer_v5.read_inventory(xml_tmp)
 
58
 
 
59
def run_benchmark(function_name, tmp_file):
 
60
    t = Timer(function_name + '()', 
 
61
              'from __main__ import ' + function_name)
 
62
    times = t.repeat(nrepeats, ntimes)
 
63
    tmp_file.seek(0, 2)
 
64
    size = tmp_file.tell()
 
65
    print 'wrote inventory to %10s %5d times, each %6d bytes, total %6dkB' \
 
66
            % (function_name, ntimes, size, (size * ntimes)>>10), 
 
67
    each = (min(times)/ntimes*1000)
 
68
    print 'in %.1fms each' % each 
 
69
    return each
 
70
 
 
71
def profileit(fn): 
 
72
    import hotshot, hotshot.stats
 
73
    prof_f = NamedTemporaryFile()
 
74
    prof = hotshot.Profile(prof_f.name)
 
75
    prof.runcall(fn) 
 
76
    prof.close()
 
77
    stats = hotshot.stats.load(prof_f.name)
 
78
    #stats.strip_dirs()
 
79
    stats.sort_stats('time')
 
80
    ## XXX: Might like to write to stderr or the trace file instead but
 
81
    ## print_stats seems hardcoded to stdout
 
82
    stats.print_stats(20)
 
83
 
 
84
if '-p' in sys.argv[1:]:
 
85
    profileit(bio_test)
 
86
else:
 
87
    bio_each = run_benchmark('bio_test', bio_tmp)
 
88
    xml_each = run_benchmark('xml_test', xml_tmp)
 
89
    print 'so bio is %.1f%% faster' % (100 * ((xml_each / bio_each) - 1))
 
90
 
 
91
# make sure it was a fair comparison
 
92
# assert 'cElementTree' in sys.modules