@@ -20,7 +20,8 @@ import Darwin
20
20
public let StringEdits = BenchmarkInfo (
21
21
name: " StringEdits " ,
22
22
runFunction: run_StringEdits,
23
- tags: [ . validation, . api, . String] )
23
+ tags: [ . validation, . api, . String] ,
24
+ legacyFactor: 100 )
24
25
25
26
var editWords : [ String ] = [
26
27
" woodshed " ,
@@ -34,42 +35,41 @@ func edits(_ word: String) -> Set<String> {
34
35
let splits = word. indices. map {
35
36
( String ( word [ ..< $0] ) , String ( word [ $0... ] ) )
36
37
}
37
-
38
+
38
39
var result : Array < String > = [ ]
39
-
40
+
40
41
for (left, right) in splits {
41
42
// drop a character
42
43
result. append ( left + right. dropFirst ( ) )
43
-
44
+
44
45
// transpose two characters
45
46
if let fst = right. first {
46
47
let drop1 = right. dropFirst ( )
47
48
if let snd = drop1. first {
48
49
result. append ( left + [ snd, fst] + drop1. dropFirst ( ) )
49
50
}
50
51
}
51
-
52
+
52
53
// replace each character with another
53
54
for letter in alphabet {
54
55
result. append ( left + [ letter] + right. dropFirst ( ) )
55
56
}
56
-
57
+
57
58
// insert rogue characters
58
59
for letter in alphabet {
59
60
result. append ( left + [ letter] + right)
60
61
}
61
62
}
62
-
63
+
63
64
// have to map back to strings right at the end
64
65
return Set ( result)
65
66
}
66
67
67
68
@inline ( never)
68
69
public func run_StringEdits( _ N: Int ) {
69
- for _ in 1 ... N*100 {
70
+ for _ in 1 ... N {
70
71
for word in editWords {
71
- _ = edits ( word)
72
+ _ = edits ( word)
72
73
}
73
74
}
74
75
}
75
-
0 commit comments