build.sh: warn without opts, don't enforce C99
[rofl0r-memcpy-test.git] / compare.py
blob351b677e7b25f5e84cb789c8c8a6748b2951672c
1 #!/usr/bin/env python
3 import sys, os
5 candidates = []
6 order = []
7 tmp = "/tmp/memcpy.tmp."
8 fna = ['']
9 for i in range(1, len(sys.argv)):
10 fn = sys.argv[i]
11 cached = True if fn.startswith('c:') else False
12 if cached: fn = fn[2:]
13 fna.append(fn)
14 if cached and os.path.exists("%s.%s"%(tmp, fn)): pass
15 elif os.system("./build.sh %s && ./test > %s.%s"%(fn, tmp, fn)):
16 sys.exit(1)
17 results = {}
18 with open("%s.%s"%(tmp, fn), "r") as f:
19 a = f.read().split('\n')
20 for x in a:
21 if not '\t' in x: continue
22 n, r = x.split('\t')
23 results[n] = r
24 if i == 1: order.append(n)
25 candidates.append(results)
27 def max(a, b):
28 return a if a > b else b
30 col_lengths = [len(x) for x in sys.argv]
31 col_lengths[0] = 4
32 for n in order: col_lengths[0] = max(len(n), col_lengths[0])
33 last_n = order[len(order)-1]
34 for i in range(len(candidates)):
35 col_lengths[i+1] = max(len(candidates[i][last_n]), col_lengths[i+1])
37 def fmt(s, col, dir=-1):
38 if dir == -1:
39 while len(s) < col_lengths[col]: s = ' ' + s
40 else:
41 while len(s) < col_lengths[col]: s = s + ' '
42 return s
44 print ("memcpy speed comparison")
45 print ("CC=%s, OPTS=%s, UNIT=ticks"%( \
46 os.environ['CC'] if 'CC' in os.environ else 'cc', \
47 os.environ['OPTS'] if 'OPTS' in os.environ else ''))
48 s = fmt("size", 0, 1)
49 for i in range(1, len(fna)):
50 s += " " + fmt(fna[i], i, 1)
51 print (s)
52 print ('-'*80)
54 for n in order:
55 s = '%s '%fmt(n, 0)
56 for i in range(len(candidates)): s += fmt(candidates[i][n], i+1) + ' '
57 print(s)