beaa62664432b126e5ad59b0060af3b352ab00dd
[scons.git] / bench / dependency-func.py
1 # __COPYRIGHT__
2 #
3 # Benchmarks for testing the selection of dependency changed functions
4 # in src/engine/Environment.py.
5
6
7 def use_a_dict(env, dep, arg):
8     func = {
9         '1111' : dep.func1,
10         '2222' : dep.func2,
11         '3333' : dep.func3,
12         '4444' : dep.func4,
13     }
14     t = env.get_type()
15     return func[t](arg)
16
17
18 def use_if_tests(env, dep, arg):
19     t = env.get_type()
20     if t == '1111':
21         func = dep.func1
22     elif t == '2222':
23         func = dep.func2
24     elif t == '3333':
25         func = dep.func3
26     elif t == '4444':
27         func = dep.func4
28     else:
29         raise Exception, "bad key %s" % t
30     return func(arg)
31
32
33 class Environment():
34     def __init__(self, t):
35         self.t = t
36     def get_type(self):
37         return self.t
38
39 class Node():
40     def func1(self, arg):
41         pass
42     def func2(self, arg):
43         pass
44     def func3(self, arg):
45         pass
46     def func4(self, arg):
47         pass
48
49 node = Node()
50
51 def Func01(t):
52     """use_a_dict"""
53     env = Environment(t)
54     for i in IterationList:
55         use_a_dict(env, node, None)
56
57 def Func02(t):
58     """use_if_tests"""
59     env = Environment(t)
60     for i in IterationList:
61         use_if_tests(env, node, None)
62
63
64
65 # Data to pass to the functions on each run.  Each entry is a
66 # three-element tuple:
67 #
68 #   (
69 #       "Label to print describing this data run",
70 #       ('positional', 'arguments'),
71 #       {'keyword' : 'arguments'},
72 #   ),
73
74 class A:
75     pass
76
77 Data = [
78     (
79         "1",
80         ('1111',),
81         {},
82     ),
83     (
84         "2",
85         ('2222',),
86         {},
87     ),
88     (
89         "3",
90         ('3333',),
91         {},
92     ),
93     (
94         "4",
95         ('4444',),
96         {},
97     ),
98 ]
99
100 # Local Variables:
101 # tab-width:4
102 # indent-tabs-mode:nil
103 # End:
104 # vim: set expandtab tabstop=4 shiftwidth=4: