3
3
import sys
4
4
import random
5
5
import multiprocessing
6
+ import argparse
6
7
7
8
from itertools import islice
8
9
9
- from pysmt .shortcuts import reset_env , get_env
10
- from pysmt .smtlib .parser import SmtLibParser
11
- from pysmt .solvers .noop import NoopSolver
10
+ from pysmt .shortcuts import reset_env , read_smtlib
12
11
13
- SMTLIB_DIR = "./"
14
12
15
13
def get_all_smt_files (target_dir = None ):
16
14
if target_dir == None :
17
- target_dir = SMTLIB_DIR
15
+ target_dir = "./"
18
16
19
17
assert os .path .exists (target_dir )
20
18
for root , _ , files in os .walk (target_dir ):
@@ -28,46 +26,52 @@ def execute_script_fname(smtfile):
28
26
print (smtfile )
29
27
reset_env ()
30
28
assert os .path .exists (smtfile )
31
- parser = SmtLibParser ()
32
- solver = NoopSolver (get_env ())
33
-
34
29
start = time .clock ()
35
- script = parser . get_script_fname (smtfile )
30
+ read_smtlib (smtfile )
36
31
end = time .clock ()
37
-
38
- script .evaluate (solver )
39
- res = solver .get_asserted_formula ()
40
- assert res is not None
41
-
42
- return (smtfile , (end - start ))
32
+ return ( (end - start ), smtfile )
43
33
44
34
45
35
def dump_stats (timings , fname ):
36
+ if fname is None :
37
+ fname = "stats.out"
46
38
with open (fname , "w" ) as f :
47
39
f .write ('filename, time\n ' )
48
40
for k in timings :
49
- f .write ('"%s" , "%s"\n ' % k )
41
+ f .write ('%f , "%s"\n ' % k )
50
42
51
43
52
44
def main ():
53
- if len (sys .argv ) != 3 :
54
- print ("usage: %s <number of files to benchmark> <statistics file>" % \
55
- sys .argv [0 ])
56
- exit (1 )
45
+ parser = argparse .ArgumentParser (description = 'SMT-LIB Parser Benchmarking' )
46
+ parser .add_argument ('--base' , type = str , nargs = '?' ,
47
+ help = 'top-directory of the benchmarks' )
48
+
49
+ parser .add_argument ('--count' , type = int , nargs = '?' ,
50
+ default = - 1 ,
51
+ help = 'number of files to benchmark' )
52
+
53
+ parser .add_argument ('--out' , type = str , default = "stats.out" , nargs = '?' ,
54
+ help = 'Where to save the statistics' )
55
+
56
+ args = parser .parse_args ()
57
57
58
58
random .seed (42 )
59
59
p = multiprocessing .Pool ()
60
60
chunks = multiprocessing .cpu_count ()
61
- file_list = list (get_all_smt_files ())
61
+ file_list = list (get_all_smt_files (args . base ))
62
62
random .shuffle (file_list )
63
- files_cnt = int (sys .argv [1 ])
63
+ if args .count == - 1 :
64
+ files_cnt = len (file_list )
65
+ else :
66
+ files_cnt = args .count
64
67
print ("Submitting %d jobs, %d at the time" % (files_cnt , chunks ))
65
68
timings = p .map (execute_script_fname , islice (file_list , files_cnt ), chunks )
66
69
67
- mean = sum (x [1 ] for x in timings ) / len (timings )
68
- print ("The mean execution time is:" , mean , "seconds" )
70
+ mean = sum (x [0 ] for x in timings ) / len (timings )
71
+ print ("The mean execution time was %0.2f seconds" % mean )
72
+ print ("The max execution time was %0.2f seconds" % max (x [0 ] for x in timings ))
69
73
70
- outfile = sys . argv [ 2 ]
74
+ outfile = args . out
71
75
dump_stats (timings , outfile )
72
76
print ("The statistics file has been generated in '%s'" % outfile )
73
77
0 commit comments