Debian Codegraph @

benchmark/bench.py

raw symbols SCIP
1 import sys, os, subprocess, signal
2
3 programs = [
4 'stl_unordered_map',
5 'abseil_flat',
6 'abseil_parallel_flat'
7 ]
8
9 test_size = 1
10 minkeys = 0
11 maxkeys = 1000
12 interval = 100
13 best_out_of = 1
14
15 if test_size == 2:
16 multiplier = 1000 * 1000
17 maxkeys = 500
18 best_out_of = 3
19
20 elif test_size == 1:
21 multiplier = 100 * 1000
22 interval = 200
23 else:
24 multiplier = 10 * 1000
25
26 # and use nice/ionice
27 # and shut down to the console
28 # and swapoff any swap files/partitions
29
30 outfile = open('output', 'w')
31
32 if len(sys.argv) > 1:
33 benchtypes = sys.argv[1:]
34 else:
35 benchtypes = ( 'random', 'lookup', 'delete',)
36 #benchtypes = ( 'lookup', )
37
38 for benchtype in benchtypes:
39 nkeys = minkeys * multiplier
40 while nkeys <= (maxkeys * multiplier):
41 for program in programs:
42 fastest_attempt = 1000000
43 fastest_attempt_data = ''
44
45 for attempt in range(best_out_of):
46 proc = subprocess.Popen(['./build/'+program, str(nkeys), benchtype], stdout=subprocess.PIPE)
47
48 # wait for the program to fill up memory and spit out its "ready" message
49 try:
50 runtime = float(proc.stdout.readline().strip())
51 except:
52 runtime = 0
53
54 ps_proc = subprocess.Popen(['ps up %d | tail -n1' % proc.pid], shell=True, stdout=subprocess.PIPE)
55 #nbytes = int(ps_proc.stdout.read().split()[4]) * 1024
56 #ps_proc.wait()
57 nbytes = 1000000
58
59 os.kill(proc.pid, signal.SIGKILL)
60 proc.wait()
61
62 if nbytes and runtime: # otherwise it crashed
63 line = ','.join(map(str, [benchtype, nkeys, program, nbytes, "%0.6f" % runtime]))
64
65 if runtime < fastest_attempt:
66 fastest_attempt = runtime
67 fastest_attempt_data = line
68
69 if fastest_attempt != 1000000:
70 print >> outfile, fastest_attempt_data
71 print fastest_attempt_data
72
73 nkeys += interval * multiplier