~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-25 14:07:04 UTC
  • Revision ID: will.newton@linaro.org-20130625140704-jp1ad8y2p8d416qk
Support multiple runs of each benchmark.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    'strcpy': DUAL_BUFFER_ALIGNMENTS,
50
50
}
51
51
 
52
 
def run(cache, variant, function, bytes, loops, alignment, quiet=False):
 
52
NUM_RUNS = 5
 
53
 
 
54
def run(cache, variant, function, bytes, loops, alignment, run_id, quiet=False):
53
55
    """Perform a single run, exercising the cache as appropriate."""
54
 
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment))
 
56
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops, alignment, run_id))
55
57
 
56
58
    if key in cache:
57
59
        got = cache[key]
58
60
    else:
59
61
        xbuild = build
60
 
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s -a %(alignment)s' % locals()
 
62
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s -a %(alignment)s -r %(run_id)s' % locals()
61
63
 
62
64
        try:
63
65
            got = subprocess.check_output(cmd.split()).strip()
65
67
            assert False, 'Error %s while running %s' % (ex, cmd)
66
68
 
67
69
    parts = got.split(':')
68
 
    took = float(parts[6])
 
70
    took = float(parts[7])
69
71
 
70
72
    cache[key] = got
71
73
 
105
107
                want = 5.0
106
108
 
107
109
                loops = int(f / math.sqrt(max(1, mid)))
108
 
                took = run(cache, variant, function, mid, loops, alignment, quiet=True)
 
110
                took = run(cache, variant, function, mid, loops, alignment, 0,
 
111
                           quiet=True)
109
112
                # Keep it reasonable for silly routines like bounce
110
113
                factor = min(20, max(0.05, want/took))
111
114
                f = f * factor
117
120
                for b in sorted(bytes):
118
121
                    # Figure out the number of loops to give a roughly consistent run
119
122
                    loops = int(f / math.sqrt(max(1, b)))
120
 
                    run(cache, variant, function, b, loops, alignment)
 
123
                    for run_id in range(0, NUM_RUNS):
 
124
                        run(cache, variant, function, b, loops, alignment,
 
125
                            run_id)
121
126
 
122
127
def run_top(cache):
123
128
    variants = sorted(HAS.keys())
150
155
            for line in f:
151
156
                line = line.strip()
152
157
                parts = line.split(':')
153
 
                cache[':'.join(parts[:6])] = line
 
158
                cache[':'.join(parts[:7])] = line
154
159
    except:
155
160
        pass
156
161