summaryrefslogtreecommitdiffstats
path: root/bench/dependency-func.py
blob: beaa62664432b126e5ad59b0060af3b352ab00dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# __COPYRIGHT__
#
# Benchmarks for testing the selection of dependency changed functions
# in src/engine/Environment.py.


def use_a_dict(env, dep, arg):
    func = {
        '1111' : dep.func1,
        '2222' : dep.func2,
        '3333' : dep.func3,
        '4444' : dep.func4,
    }
    t = env.get_type()
    return func[t](arg)


def use_if_tests(env, dep, arg):
    t = env.get_type()
    if t == '1111':
        func = dep.func1
    elif t == '2222':
        func = dep.func2
    elif t == '3333':
        func = dep.func3
    elif t == '4444':
        func = dep.func4
    else:
        raise Exception, "bad key %s" % t
    return func(arg)


class Environment():
    def __init__(self, t):
        self.t = t
    def get_type(self):
        return self.t

class Node():
    def func1(self, arg):
        pass
    def func2(self, arg):
        pass
    def func3(self, arg):
        pass
    def func4(self, arg):
        pass

node = Node()

def Func01(t):
    """use_a_dict"""
    env = Environment(t)
    for i in IterationList:
        use_a_dict(env, node, None)

def Func02(t):
    """use_if_tests"""
    env = Environment(t)
    for i in IterationList:
        use_if_tests(env, node, None)



# Data to pass to the functions on each run.  Each entry is a
# three-element tuple:
#
#   (
#       "Label to print describing this data run",
#       ('positional', 'arguments'),
#       {'keyword' : 'arguments'},
#   ),

class A:
    pass

Data = [
    (
        "1",
        ('1111',),
        {},
    ),
    (
        "2",
        ('2222',),
        {},
    ),
    (
        "3",
        ('3333',),
        {},
    ),
    (
        "4",
        ('4444',),
        {},
    ),
]

# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4: