mercurial/dicthelpers.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Fri, 16 May 2014 13:18:57 -0700
changeset 21424 d13b4ecdb680
parent 18894 ed46c2b98b0d
permissions -rw-r--r--
test: split test-largefile.t in multiple file The `test-largefiles.t` unified test is significantly longer (about 30%) than any other tests in the mercurial test suite. As a result, its is alway the last test my test runner is waiting for at the end of a run. In practice, this means that `test-largefile.t` is wasting half a minute of my life every times I'm running the mercurial test suites. This probably mean more a few cumulated day by now. I've finally decided to split it up in multiple smaller tests to bring it back in reasonable length. This changeset extracts independent test cases in two files. One dedicated to wire protocole testing, and another one dedicated to all other tests that could be independently extracted. No test case were haltered in the making of this changeset. Various timing available below. All timing have been done on a with 90 jobs on a 64 cores machine. Similar result are shown on firefly (20 jobs on 12 core). General timing of the whole run -------------------------------- We see a 25% real time improvement for no significant cpu time impact. Before split: real 2m1.149s user 58m4.662s sys 11m28.563s After split: real 1m31.977s user 57m45.993s sys 11m33.634s Last test to finish (using run-test.py --time) ---------------------------------------------- test-largefile.t is now finishing at the same time than other slow tests. Before split: Time Test 119.280 test-largefiles.t 93.995 test-mq.t 89.897 test-subrepo.t 86.920 test-glog.t 85.508 test-rename-merge2.t 83.594 test-revset.t 79.824 test-keyword.t 78.077 test-mq-header-date.t After split: Time Test 90.414 test-mq.t 88.594 test-largefiles.t 85.363 test-subrepo.t 81.059 test-glog.t 78.927 test-rename-merge2.t 78.021 test-revset.t 77.777 test-command-template.t Timing of largefile test themself ----------------------------------- Running only tests prefixed with "test-largefiles". No significant change in cumulated time. Before: Time Test 58.673 test-largefiles.t 2.931 test-largefiles-cache.t 0.583 test-largefiles-small-disk.t After: Time Test 31.754 test-largefiles.t 17.460 test-largefiles-misc.t 8.888 test-largefiles-wireproto.t 2.864 test-largefiles-cache.t 0.580 test-largefiles-small-disk.t
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18820
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     1
# dicthelpers.py - helper routines for Python dicts
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     2
#
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     3
# Copyright 2013 Facebook
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     4
#
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
     7
18847
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
     8
def diff(d1, d2, default=None):
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
     9
    '''Return all key-value pairs that are different between d1 and d2.
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    10
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    11
    This includes keys that are present in one dict but not the other, and
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    12
    keys whose values are different. The return value is a dict with values
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    13
    being pairs of values from d1 and d2 respectively, and missing values
18894
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    14
    treated as default, so if a value is missing from one dict and the same as
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    15
    default in the other, it will not be returned.'''
18820
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    16
    res = {}
18847
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    17
    if d1 is d2:
18820
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    18
        # same dict, so diff is empty
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    19
        return res
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    20
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    21
    for k1, v1 in d1.iteritems():
18894
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    22
        v2 = d2.get(k1, default)
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    23
        if v1 != v2:
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    24
            res[k1] = (v1, v2)
18820
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    25
18847
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    26
    for k2 in d2:
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    27
        if k2 not in d1:
18894
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    28
            v2 = d2[k2]
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    29
            if v2 != default:
ed46c2b98b0d dicthelpers.diff: compare against default for missing values
Siddharth Agarwal <sid0@fb.com>
parents: 18847
diff changeset
    30
                res[k2] = (default, v2)
18847
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    31
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    32
    return res
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    33
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    34
def join(d1, d2, default=None):
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    35
    '''Return all key-value pairs from both d1 and d2.
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    36
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    37
    This is akin to an outer join in relational algebra. The return value is a
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    38
    dict with values being pairs of values from d1 and d2 respectively, and
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    39
    missing values represented as default.'''
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    40
    res = {}
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    41
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    42
    for k1, v1 in d1.iteritems():
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    43
        if k1 in d2:
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    44
            res[k1] = (v1, d2[k1])
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    45
        else:
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    46
            res[k1] = (v1, default)
40c679748fa9 dicthelpers: inline diff and join code
Siddharth Agarwal <sid0@fb.com>
parents: 18846
diff changeset
    47
18820
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    48
    if d1 is d2:
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    49
        return res
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    50
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    51
    for k2 in d2:
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    52
        if k2 not in d1:
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    53
            res[k2] = (default, d2[k2])
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    54
a45e44d76c81 mercurial: implement diff and join for dicts
Siddharth Agarwal <sid0@fb.com>
parents:
diff changeset
    55
    return res