42
42
import sys
43
43
44
44
45
+ # This regular expression is looking for Swift functions named `bench_*`
46
+ # that take no arguments and return an Int. The Swift code for such
47
+ # a function is:
48
+ #
49
+ # func bench_myname() {
50
+ # // function body goes here
51
+ # }
52
+ BENCH_RE = re .compile (
53
+ r"^\s*" # whitespace at the start of the line
54
+ r"func\s+" # 'func' keyword, which must be followed by
55
+ # at least one space
56
+ r"bench_([a-zA-Z0-9_]+)\s*"
57
+ # name of the function
58
+ r"\s*\(\s*\)" # argument list
59
+ r"\s*->\s*Int\s*" # return type
60
+ r"({)?" # opening brace of the function body
61
+ r"\s*$" # whitespace ot the end of the line
62
+ )
63
+
64
+
45
65
def pstdev (sample ):
46
66
"""Given a list of numbers, return the population standard deviation.
47
67
@@ -85,7 +105,9 @@ def parse_arguments(self):
85
105
"-v" , "--verbosity" ,
86
106
help = "increase output verbosity" , type = int )
87
107
parser .add_argument ("files" , help = "input files" , nargs = '+' )
88
- parser .add_argument ('-c' , '--compiler' , help = "compiler to use" )
108
+ parser .add_argument (
109
+ '-c' , '--compiler' ,
110
+ help = "compiler to use" , default = "swiftc" )
89
111
parser .add_argument (
90
112
'-t' , '--timelimit' ,
91
113
help = "Time limit for every test" , type = int )
@@ -98,12 +120,9 @@ def parse_arguments(self):
98
120
if args .verbosity :
99
121
self .verbose_level = args .verbosity
100
122
self .sources = args .files
123
+ self .compiler = args .compiler
101
124
if args .flags :
102
125
self .opt_flags = args .flags
103
- if args .compiler :
104
- self .compiler = args .compiler
105
- else :
106
- self .compiler = 'swiftc'
107
126
if args .timelimit and args .timelimit > 0 :
108
127
self .time_limit = args .timelimit
109
128
if args .sampletime and args .sampletime > 0 :
@@ -171,15 +190,12 @@ def process_source(self, name):
171
190
main()
172
191
"""
173
192
174
- bench_re = re .compile (
175
- "^\s*func\s\s*bench_([a-zA-Z0-9_]+)" +
176
- "\s*\(\s*\)\s*->\s*Int\s*({)?\s*$" )
177
193
with open (name ) as f :
178
194
lines = list (f )
179
195
output = header
180
196
looking_for_curly_brace = False
181
197
test_names = []
182
- for l in lines :
198
+ for lineno , l in enumerate ( lines , start = 1 ) :
183
199
if looking_for_curly_brace :
184
200
output += l
185
201
if "{" not in l :
@@ -188,13 +204,13 @@ def process_source(self, name):
188
204
output += into_bench
189
205
continue
190
206
191
- m = bench_re .match (l )
207
+ m = BENCH_RE .match (l )
192
208
if m :
193
209
output += before_bench
194
210
output += l
195
211
bench_name = m .group (1 )
196
- # TODO: Keep track of the line number as well
197
- self . log ( "Benchmark found: %s" % bench_name , 3 )
212
+ self . log ( "Benchmark found: %s ( line %d)" %
213
+ ( bench_name , lineno ) , 3 )
198
214
self .tests [
199
215
name + ":" +
200
216
bench_name ] = Test (bench_name , name , "" , "" )
0 commit comments