~linaro-toolchain-dev/cortex-strings/trunk

« back to all changes in this revision

Viewing changes to scripts/bench.py

  • Committer: Will Newton
  • Date: 2013-06-14 09:20:08 UTC
  • Revision ID: will.newton@linaro.org-20130614092008-3am3v7itqy544uch
Allow running a subset of benchmarks.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    'plain': 'memset memcpy strcmp strcpy',
34
34
}
35
35
 
36
 
BOUNCE_ALIGNMENTS = ['1']
37
 
SINGLE_BUFFER_ALIGNMENTS = ['1', '2', '4', '8', '16', '32']
38
 
DUAL_BUFFER_ALIGNMENTS = ['1:32', '2:32', '4:32', '8:32', '16:32', '32:32']
39
 
 
40
 
ALIGNMENTS = {
41
 
    'bounce': BOUNCE_ALIGNMENTS,
42
 
    'memchr': SINGLE_BUFFER_ALIGNMENTS,
43
 
    'memset': SINGLE_BUFFER_ALIGNMENTS,
44
 
    'strchr': SINGLE_BUFFER_ALIGNMENTS,
45
 
    'strlen': SINGLE_BUFFER_ALIGNMENTS,
46
 
    'memcmp': DUAL_BUFFER_ALIGNMENTS,
47
 
    'memcpy': DUAL_BUFFER_ALIGNMENTS,
48
 
    'strcmp': DUAL_BUFFER_ALIGNMENTS,
49
 
    'strcpy': DUAL_BUFFER_ALIGNMENTS,
50
 
}
51
 
 
52
 
NUM_RUNS = 5
53
 
 
54
 
def run(cache, variant, function, bytes, loops, alignment, run_id, quiet=False):
 
36
def run(cache, variant, function, bytes, loops, alignment=8, quiet=False):
55
37
    """Perform a single run, exercising the cache as appropriate."""
56
 
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment, run_id))
 
38
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment))
57
39
 
58
40
    if key in cache:
59
41
        got = cache[key]
60
42
    else:
61
43
        xbuild = build
62
 
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s -a %(alignment)s -r %(run_id)s' % locals()
 
44
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s -a %(alignment)s' % locals()
63
45
 
64
46
        try:
65
47
            got = subprocess.check_output(cmd.split()).strip()
67
49
            assert False, 'Error %s while running %s' % (ex, cmd)
68
50
 
69
51
    parts = got.split(':')
70
 
    took = float(parts[7])
 
52
    took = float(parts[5])
71
53
 
72
54
    cache[key] = got
73
55
 
77
59
 
78
60
    return took
79
61
 
80
 
def run_many(cache, variants, bytes, all_functions):
 
62
def run_many(cache, variants, bytes, alignments, all_functions):
81
63
    # We want the data to come out in a useful order.  So fix an
82
64
    # alignment and function, and do all sizes for a variant first
83
65
    bytes = sorted(bytes)
84
 
    mid = bytes[int(len(bytes)/1.5)]
 
66
    mid = bytes[len(bytes)/2]
85
67
 
86
68
    if not all_functions:
87
69
        # Use the ordering in 'this' as the default
93
75
                if function not in all_functions:
94
76
                    all_functions.append(function)
95
77
 
96
 
    for function in all_functions:
97
 
        for alignment in ALIGNMENTS[function]:
 
78
    for alignment in alignments:
 
79
        for function in all_functions:
98
80
            for variant in variants:
99
81
                if function not in HAS[variant].split():
100
82
                    continue
107
89
                want = 5.0
108
90
 
109
91
                loops = int(f / math.sqrt(max(1, mid)))
110
 
                took = run(cache, variant, function, mid, loops, alignment, 0,
111
 
                           quiet=True)
 
92
                took = run(cache, variant, function, mid, loops, alignment, quiet=True)
112
93
                # Keep it reasonable for silly routines like bounce
113
94
                factor = min(20, max(0.05, want/took))
114
95
                f = f * factor
120
101
                for b in sorted(bytes):
121
102
                    # Figure out the number of loops to give a roughly consistent run
122
103
                    loops = int(f / math.sqrt(max(1, b)))
123
 
                    for run_id in range(0, NUM_RUNS):
124
 
                        run(cache, variant, function, b, loops, alignment,
125
 
                            run_id)
 
104
                    run(cache, variant, function, b, loops, alignment)
126
105
 
127
106
def run_top(cache):
128
107
    variants = sorted(HAS.keys())
143
122
            steps = int(round(math.log(top) / math.log(step)))
144
123
            bytes.extend([int(step**x) for x in range(0, steps+1)])
145
124
 
146
 
    run_many(cache, variants, bytes, functions)
 
125
    alignments = [8, 16, 4, 1, 2, 32]
 
126
 
 
127
    run_many(cache, variants, bytes, alignments, functions)
147
128
 
148
129
def main():
149
130
    cachename = 'cache.txt'
155
136
            for line in f:
156
137
                line = line.strip()
157
138
                parts = line.split(':')
158
 
                cache[':'.join(parts[:7])] = line
 
139
                cache[':'.join(parts[:5])] = line
159
140
    except:
160
141
        pass
161
142