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
|
#!/usr/bin/env python
import subprocess
import math
import sys
build = '../build/try-'
def run(cache, variant, function, bytes, loops):
key = ':'.join('%s' % x for x in (variant, function, bytes, loops))
if key in cache:
print cache[key]
else:
xbuild = build
cmd = '%(xbuild)s%(variant)s -t %(function)s -c %(bytes)s -l %(loops)s' % locals()
got = subprocess.check_output(cmd.split()).strip()
cache[key] = got
print got
sys.stdout.flush()
def run_bytes(cache, variant, function, bytes):
for b in bytes:
loops = int(500000000/5 / math.sqrt(b))
run(cache, variant, function, b, loops)
def run_functions(cache, variant, functions, bytes):
for function in functions:
run_bytes(cache, variant, function, bytes)
HAS = {
'this': 'strcmp strcpy memchr strchr strlen memcpy memset',
'bionc': 'strlen memset memcpy',
'glibc': 'memset strlen memcpy strcmp strcpy memchr strchr',
'newlib': 'strcmp strlen strcpy',
'plain': 'memset memcpy strcmp strcpy',
'csl': 'memcpy memset'
}
def run_variant(cache, variant, bytes):
functions = HAS[variant].split()
run_functions(cache, variant, functions, bytes)
def run_variants(cache, variants, bytes):
for variant in variants:
run_variant(cache, variant, bytes)
def run_top(cache):
variants = HAS.keys()
bytes = [2**x for x in range(1, 12)]
run_variants(cache, variants, bytes)
def main():
cachename = 'cache.txt'
cache = {}
try:
with open(cachename) as f:
for line in f:
line = line.strip()
parts = line.split(':')
cache[':'.join(parts[:4])] = line
except:
pass
try:
run_top(cache)
finally:
with open(cachename, 'w') as f:
for line in cache.values():
print >> f, line
main()
|