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

« back to all changes in this revision

Viewing changes to scripts/bench.py

  • Committer: Michael Hope
  • Date: 2011-08-31 04:04:26 UTC
  • Revision ID: michael.hope@linaro.org-20110831040426-fjpxcmw0zmsrh8cp
Added some scripts to run the benchmarks and to plot the results.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
import subprocess
 
4
import math
 
5
import sys
 
6
 
 
7
build = '../build/try-'
 
8
 
 
9
 
 
10
def run(cache, variant, function, bytes, loops):
 
11
    key = ':'.join('%s' % x for x in (variant, function, bytes, loops))
 
12
 
 
13
    if key in cache:
 
14
        print cache[key]
 
15
    else:
 
16
        xbuild = build
 
17
        cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s' % locals()
 
18
 
 
19
        got = subprocess.check_output(cmd.split()).strip()
 
20
        cache[key] = got
 
21
        print got
 
22
 
 
23
    sys.stdout.flush()
 
24
 
 
25
 
 
26
def run_bytes(cache, variant, function, bytes):
 
27
    for b in bytes:
 
28
        loops = int(500000000/5 / math.sqrt(b))
 
29
        run(cache, variant, function, b, loops)
 
30
 
 
31
 
 
32
def run_functions(cache, variant, functions, bytes):
 
33
    for function in functions:
 
34
        run_bytes(cache, variant, function, bytes)
 
35
 
 
36
 
 
37
HAS = {
 
38
    'this': 'strcmp strcpy memchr strchr strlen memcpy memset',
 
39
    'bionc': 'strlen memset memcpy',
 
40
    'glibc': 'memset strlen memcpy  strcmp strcpy memchr strchr',
 
41
    'newlib': 'strcmp strlen strcpy',
 
42
    'plain': 'memset memcpy strcmp strcpy',
 
43
    'csl': 'memcpy memset'
 
44
}
 
45
 
 
46
 
 
47
def run_variant(cache, variant, bytes):
 
48
    functions = HAS[variant].split()
 
49
    run_functions(cache, variant, functions, bytes)
 
50
 
 
51
 
 
52
def run_variants(cache, variants, bytes):
 
53
    for variant in variants:
 
54
        run_variant(cache, variant, bytes)
 
55
 
 
56
 
 
57
def run_top(cache):
 
58
    variants = HAS.keys()
 
59
    bytes = [2**x for x in range(1, 12)]
 
60
    run_variants(cache, variants, bytes)
 
61
 
 
62
 
 
63
def main():
 
64
    cachename = 'cache.txt'
 
65
 
 
66
    cache = {}
 
67
 
 
68
    try:
 
69
        with open(cachename) as f:
 
70
            for line in f:
 
71
                line = line.strip()
 
72
                parts = line.split(':')
 
73
                cache[':'.join(parts[:4])] = line
 
74
    except:
 
75
        pass
 
76
 
 
77
    try:
 
78
        run_top(cache)
 
79
    finally:
 
80
        with open(cachename, 'w') as f:
 
81
            for line in cache.values():
 
82
                print >> f, line
 
83
 
 
84
main()