Skip to content

Commit 2c8ae98

Browse files
authored
Python3 compatibility for Benchmarks (#33039)
Three issues addressed here: 1. Dependency on dictionary iteration order CharacterProperties.swift.gyb iterated a dictionary to produce its output. Changed this to a list of tuples to ensure the order is predictable. 2. Python3 `map` returns an iterator, not a list Changed a bunch of `map` calls to `list(map(...))` to ensure the result is a list 3. Python3 `int()` expects a string, won't accept a list of characters Added a concatenation step that is effectively a no-op on Python2
1 parent da998ba commit 2c8ae98

9 files changed

+172
-172
lines changed

benchmark/single-source/CharacterProperties.swift

Lines changed: 142 additions & 142 deletions
Large diffs are not rendered by default.

benchmark/single-source/CharacterProperties.swift.gyb

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ extension Character {
5252
var firstScalar: UnicodeScalar { return unicodeScalars.first! }
5353
}
5454

55-
% Properties = { "Alphanumeric": "alphanumerics", \
56-
% "Capitalized": "capitalizedLetters", \
57-
% "Control": "controlCharacters", \
58-
% "Decimal": "decimalDigits", \
59-
% "Letter": "letters", \
60-
% "Lowercase": "lowercaseLetters", \
61-
% "Uppercase": "uppercaseLetters", \
62-
% "Newline": "newlines", \
63-
% "Whitespace": "whitespaces", \
64-
% "Punctuation": "punctuationCharacters" \
65-
% }
55+
% Properties = [ ( "Alphanumeric", "alphanumerics"),
56+
% ( "Capitalized", "capitalizedLetters"),
57+
% ( "Control", "controlCharacters"),
58+
% ( "Decimal", "decimalDigits"),
59+
% ( "Letter", "letters"),
60+
% ( "Lowercase", "lowercaseLetters"),
61+
% ( "Uppercase", "uppercaseLetters"),
62+
% ( "Newline", "newlines"),
63+
% ( "Whitespace", "whitespaces"),
64+
% ( "Punctuation", "punctuationCharacters")
65+
% ]
6666

6767
// Fetch the CharacterSet for every call
68-
% for Property, Set in Properties.items():
68+
% for Property, Set in Properties:
6969
func is${Property}(_ c: Character) -> Bool {
7070
return CharacterSet.${Set}.contains(c.firstScalar)
7171
}
7272
% end
7373

7474
// Stash the set
75-
% for Property, Set in Properties.items():
75+
% for Property, Set in Properties:
7676
let ${Set} = CharacterSet.${Set}
7777
func is${Property}Stashed(_ c: Character) -> Bool {
7878
return ${Set}.contains(c.firstScalar)
@@ -81,13 +81,13 @@ func is${Property}Stashed(_ c: Character) -> Bool {
8181

8282
func setupStash() {
8383
blackHole(workload)
84-
% for Property, Set in Properties.items():
84+
% for Property, Set in Properties:
8585
blackHole(${Set})
8686
% end
8787
}
8888

8989
// Memoize the stashed set
90-
% for Property, Set in Properties.items():
90+
% for Property, Set in Properties:
9191
var ${Set}Memo = Set<UInt32>()
9292
func is${Property}StashedMemo(_ c: Character) -> Bool {
9393
let scalar = c.firstScalar
@@ -102,7 +102,7 @@ func is${Property}StashedMemo(_ c: Character) -> Bool {
102102

103103
func setupMemo() {
104104
blackHole(workload)
105-
% for Property, Set in Properties.items():
105+
% for Property, Set in Properties:
106106
blackHole(${Set}Memo)
107107
% end
108108
}
@@ -130,7 +130,7 @@ func precompute(_ charSet: CharacterSet, capacity: Int) -> Set<UInt32> {
130130
capitalizedLetters=31
131131
)
132132
}%
133-
% for Property, Set in Properties.items():
133+
% for Property, Set in Properties:
134134
var ${Set}Precomputed: Set<UInt32> =
135135
precompute(${Set}, capacity: ${precomputed_capacity[Set]})
136136
func is${Property}Precomputed(_ c: Character) -> Bool {
@@ -140,7 +140,7 @@ func is${Property}Precomputed(_ c: Character) -> Bool {
140140

141141
func setupPrecomputed() {
142142
blackHole(workload)
143-
% for Property, Set in Properties.items():
143+
% for Property, Set in Properties:
144144
blackHole(${Set}Precomputed)
145145
%#// print("${Set}: \(${Set}Precomputed.count)")
146146
% end
@@ -171,7 +171,7 @@ let workload = """
171171
public func run_CharacterPropertiesFetch(_ N: Int) {
172172
for _ in 1...N {
173173
for c in workload {
174-
% for Property, Set in Properties.items():
174+
% for Property, Set in Properties:
175175
blackHole(is${Property}(c))
176176
% end
177177
}
@@ -182,7 +182,7 @@ public func run_CharacterPropertiesFetch(_ N: Int) {
182182
public func run_CharacterPropertiesStashed(_ N: Int) {
183183
for _ in 1...N {
184184
for c in workload {
185-
% for Property, Set in Properties.items():
185+
% for Property, Set in Properties:
186186
blackHole(is${Property}Stashed(c))
187187
% end
188188
}
@@ -193,7 +193,7 @@ public func run_CharacterPropertiesStashed(_ N: Int) {
193193
public func run_CharacterPropertiesStashedMemo(_ N: Int) {
194194
for _ in 1...N {
195195
for c in workload {
196-
% for Property, Set in Properties.items():
196+
% for Property, Set in Properties:
197197
blackHole(is${Property}StashedMemo(c))
198198
% end
199199
}
@@ -204,7 +204,7 @@ public func run_CharacterPropertiesStashedMemo(_ N: Int) {
204204
public func run_CharacterPropertiesPrecomputed(_ N: Int) {
205205
for _ in 1...N {
206206
for c in workload {
207-
% for Property, Set in Properties.items():
207+
% for Property, Set in Properties:
208208
blackHole(is${Property}Precomputed(c))
209209
% end
210210
}

benchmark/single-source/DropFirst.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Sequences = [
4040
]
4141
def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy')
4242

43-
Sequences = Sequences + map(lazy, Sequences)
43+
Sequences = Sequences + list(map(lazy, Sequences))
4444
}%
4545

4646
public let DropFirst = [

benchmark/single-source/DropLast.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Sequences = [
4040
]
4141
def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy')
4242

43-
Sequences = Sequences + map(lazy, Sequences)
43+
Sequences = Sequences + list(map(lazy, Sequences))
4444
}%
4545

4646
public let DropLast = [

benchmark/single-source/DropWhile.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Sequences = [
4040
]
4141
def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy')
4242

43-
Sequences = Sequences + map(lazy, Sequences)
43+
Sequences = Sequences + list(map(lazy, Sequences))
4444
}%
4545

4646
public let DropWhile = [

benchmark/single-source/ExistentialPerformance.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func next(_ x: inout Int, upto mod: Int) {
169169
x = (x + 1) % (mod + 1)
170170
}
171171

172-
% for (V, i) in [(v, int(filter(str.isdigit, v))) for v in Vals]:
172+
% for (V, i) in [(v, int(''.join(filter(str.isdigit, v)))) for v in Vals]:
173173
struct ${V} : Existential {${
174174
''.join(['\n var f{0}: Int = {1}'.format(vi, v)
175175
for (vi, v) in Vars[0:i]]) +
@@ -208,7 +208,7 @@ class Klazz { // body same as Val2
208208
}
209209
}
210210

211-
% for (V, i) in [(v, int(filter(str.isdigit, v))) for v in Refs]:
211+
% for (V, i) in [(v, int(''.join(filter(str.isdigit, v)))) for v in Refs]:
212212
struct ${V} : Existential {
213213
${'\n '.join([('var f{0}: Klazz = Klazz()'.format(vi) if vi < 3 else
214214
'var f3: Int = 0') for (vi, _) in Vars[0:i]])}

benchmark/single-source/Prefix.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Sequences = [
3939
]
4040
def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy')
4141

42-
Sequences = Sequences + map(lazy, Sequences)
42+
Sequences = Sequences + list(map(lazy, Sequences))
4343
}%
4444

4545
public let Prefix = [

benchmark/single-source/PrefixWhile.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Sequences = [
3939
]
4040
def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy')
4141

42-
Sequences = Sequences + map(lazy, Sequences)
42+
Sequences = Sequences + list(map(lazy, Sequences))
4343
}%
4444

4545
public let PrefixWhile = [

benchmark/single-source/Suffix.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Sequences = [
3939
]
4040
def lazy (NameExpr) : return (NameExpr[0] + 'Lazy', '(' + NameExpr[1] + ').lazy')
4141

42-
Sequences = Sequences + map(lazy, Sequences)
42+
Sequences = Sequences + list(map(lazy, Sequences))
4343
}%
4444

4545
public let Suffix = [

0 commit comments

Comments
 (0)