8
8
import os , re , sys
9
9
from contextlib import nested
10
10
from glob import glob
11
- from subprocess import check_call , Popen , PIPE
11
+ from subprocess import check_call , Popen , PIPE , CalledProcessError
12
12
from timeit import timeit
13
13
14
14
template = r'''
@@ -175,8 +175,11 @@ def benchmark(flags):
175
175
command = 'check_call({})' .format (
176
176
[compiler_path , '-std=c++14' , '-o' , output_filename , include_dir ] + sources + flags )
177
177
result = Result ()
178
- result .time = timeit (
179
- command , setup = 'from subprocess import check_call' , number = 1 )
178
+ try :
179
+ result .time = timeit (
180
+ command , setup = 'from subprocess import check_call' , number = 1 )
181
+ except CalledProcessError :
182
+ return None
180
183
print ('Compile time: {:.2f}s' .format (result .time ))
181
184
result .size = os .stat (output_filename ).st_size
182
185
print ('Size: {}' .format (result .size ))
@@ -190,6 +193,7 @@ def benchmark(flags):
190
193
if not expected_output :
191
194
expected_output = output
192
195
elif output != expected_output :
196
+ print (output )
193
197
raise Exception ("output doesn't match" )
194
198
sys .stdout .flush ()
195
199
return result
@@ -244,14 +248,21 @@ def print_table(table, *formats):
244
248
def to_kib (n ):
245
249
return int (round (n / 1024.0 ))
246
250
251
+ exclude_list = []
247
252
NUM_RUNS = 3
248
253
for config , flags in configs :
249
254
results = {}
250
255
for i in range (NUM_RUNS ):
251
256
for method , method_flags in methods :
257
+ if method in exclude_list :
258
+ continue
252
259
print ('Benchmarking' , config , method )
253
260
sys .stdout .flush ()
254
261
new_result = benchmark (flags + method_flags + sys .argv [1 :])
262
+ if not new_result :
263
+ exclude_list .append (method )
264
+ print (method + ' is not available' )
265
+ continue
255
266
if method not in results :
256
267
results [method ] = new_result
257
268
continue
@@ -265,6 +276,8 @@ def to_kib(n):
265
276
('Method' , 'Compile Time, s' , 'Executable size, KiB' , 'Stripped size, KiB' )
266
277
]
267
278
for method , method_flags in methods :
279
+ if method not in results :
280
+ continue
268
281
result = results [method ]
269
282
table .append (
270
283
(method , result .time , to_kib (result .size ), to_kib (result .stripped_size )))
0 commit comments