forked from mackstann/hash-table-shootout
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bench_number.py
82 lines (68 loc) · 2.4 KB
/
bench_number.py
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
import sys, os, subprocess, signal
programs = [
'LuaHashMapPointer51',
'LuaHashMapPointer52',
'LuaHashMapPointerJIT',
'LuaHashMapNumber51',
'LuaHashMapNumber52',
'LuaHashMapNumberJIT',
# 'stl_unordered_map',
# 'perl_hash',
# 'python_dict',
# 'ruby_hash',
]
#
# 'glib_hash_table',
# 'stl_unordered_map',
# 'boost_unordered_map',
# 'google_sparse_hash_map',
# 'google_dense_hash_map',
# 'qt_qhash',
# 'python_dict',
# 'ruby_hash',
minkeys = 10*1000*1000
maxkeys = 30*1000*1000
interval = 10*1000*1000
best_out_of = 2
# for the final run, use this:
#minkeys = 2*1000*1000
#maxkeys = 40*1000*1000
#interval = 2*1000*1000
#best_out_of = 3
# and use nice/ionice
# and shut down to the console
# and swapoff any swap files/partitions
outfile = open('output', 'w')
if len(sys.argv) > 1:
benchtypes = sys.argv[1:]
else:
benchtypes = ('sequential', 'random', 'delete', 'sequentialstring', 'randomstring', 'deletestring')
# benchtypes = ('sequentialstring', 'randomstring')
# benchtypes = ('randomstring', 'deletestring')
for benchtype in benchtypes:
nkeys = minkeys
while nkeys <= maxkeys:
for program in programs:
fastest_attempt = 1000000
fastest_attempt_data = ''
for attempt in range(best_out_of):
proc = subprocess.Popen(['./build/'+program, str(nkeys), benchtype], stdout=subprocess.PIPE)
# wait for the program to fill up memory and spit out its "ready" message
try:
runtime = float(proc.stdout.readline().strip())
except:
runtime = 0
ps_proc = subprocess.Popen(['ps up %d | tail -n1' % proc.pid], shell=True, stdout=subprocess.PIPE)
nbytes = int(ps_proc.stdout.read().split()[4]) * 1024
ps_proc.wait()
os.kill(proc.pid, signal.SIGKILL)
proc.wait()
if nbytes and runtime: # otherwise it crashed
line = ','.join(map(str, [benchtype, nkeys, program, nbytes, "%0.6f" % runtime]))
if runtime < fastest_attempt:
fastest_attempt = runtime
fastest_attempt_data = line
if fastest_attempt != 1000000:
print >> outfile, fastest_attempt_data
print fastest_attempt_data
nkeys += interval