Skip to content

Commit 54aa105

Browse files
committed
[benchmark] StringDistance: Add ASCII cases
1 parent 3edb034 commit 54aa105

File tree

1 file changed

+77
-25
lines changed

1 file changed

+77
-25
lines changed

benchmark/single-source/StringDistance.swift

Lines changed: 77 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,65 @@ import TestsUtils
1414

1515
public let benchmarks: [BenchmarkInfo] = [
1616
BenchmarkInfo(
17-
name: "StringDistance.characters",
17+
name: "StringDistance.characters.mixed",
1818
runFunction: { n in
19-
run_characters(string: sampleString, ranges: sampleRanges, n: n)
19+
run_characters(string: mixedString, ranges: mixedRanges, n: n)
2020
},
2121
tags: [.api, .String],
22-
setUpFunction: { _ = sampleRanges }),
22+
setUpFunction: { blackHole(mixedRanges) }),
2323
BenchmarkInfo(
24-
name: "StringDistance.scalars",
24+
name: "StringDistance.scalars.mixed",
2525
runFunction: { n in
26-
run_scalars(string: sampleString, ranges: sampleRanges, n: n)
26+
run_scalars(string: mixedString, ranges: mixedRanges, n: n)
2727
},
2828
tags: [.api, .String],
29-
setUpFunction: { _ = sampleRanges }),
29+
setUpFunction: { blackHole(mixedRanges) }),
3030
BenchmarkInfo(
31-
name: "StringDistance.utf16",
31+
name: "StringDistance.utf16.mixed",
3232
runFunction: { n in
33-
run_utf16(string: sampleString, ranges: sampleRanges, n: n)
33+
run_utf16(string: mixedString, ranges: mixedRanges, n: n)
3434
},
3535
tags: [.api, .String],
36-
setUpFunction: { _ = sampleRanges }),
36+
setUpFunction: { blackHole(mixedRanges) }),
3737
BenchmarkInfo(
38-
name: "StringDistance.utf8",
38+
name: "StringDistance.utf8.mixed",
3939
runFunction: { n in
40-
run_utf8(string: sampleString, ranges: sampleRanges, n: n)
40+
run_utf8(string: mixedString, ranges: mixedRanges, n: n)
4141
},
4242
tags: [.api, .String],
43-
setUpFunction: { _ = sampleRanges }),
43+
setUpFunction: { blackHole(mixedRanges) }),
44+
BenchmarkInfo(
45+
name: "StringDistance.characters.ascii",
46+
runFunction: { n in
47+
run_characters(string: asciiString, ranges: asciiRanges, n: n)
48+
},
49+
tags: [.api, .String],
50+
setUpFunction: { blackHole(asciiRanges) }),
51+
BenchmarkInfo(
52+
name: "StringDistance.scalars.ascii",
53+
runFunction: { n in
54+
run_scalars(string: asciiString, ranges: asciiRanges, n: n)
55+
},
56+
tags: [.api, .String],
57+
setUpFunction: { blackHole(asciiRanges) }),
58+
BenchmarkInfo(
59+
name: "StringDistance.utf16.ascii",
60+
runFunction: { n in
61+
run_utf16(string: asciiString, ranges: asciiRanges, n: n)
62+
},
63+
tags: [.api, .String],
64+
setUpFunction: { blackHole(asciiRanges) }),
65+
BenchmarkInfo(
66+
name: "StringDistance.utf8.ascii",
67+
runFunction: { n in
68+
run_utf8(string: asciiString, ranges: asciiRanges, n: n)
69+
},
70+
tags: [.api, .String],
71+
setUpFunction: { blackHole(asciiRanges) }),
4472
]
4573

4674

47-
let sampleString =
48-
#"""
75+
let mixedString = #"""
4976
The powerful programming language that is also easy to learn.
5077
손쉽게 학습할 수 있는 강력한 프로그래밍 언어.
5178
🪙 A 🥞 short 🍰 piece 🫘 of 🌰 text 👨‍👨‍👧‍👧 with 👨‍👩‍👦 some 🚶🏽 emoji 🇺🇸🇨🇦 characters 🧈
@@ -62,17 +89,42 @@ let sampleString =
6289
e̶̢͕̦̜͔̘̘̝͈̪̖̺̥̺̹͉͎͈̫̯̯̻͑͑̿̽͂̀̽͋́̎̈́̈̿͆̿̒̈́̽̔̇͐͛̀̓͆̏̾̀̌̈́̆̽̕ͅ
6390
"""#
6491

65-
let sampleRanges = (
66-
generateRanges(for: sampleString, by: 1)
67-
+ generateRanges(for: sampleString, by: 2)
68-
+ generateRanges(for: sampleString, by: 4)
69-
+ generateRanges(for: sampleString, by: 8)
70-
+ generateRanges(for: sampleString, by: 16)
71-
+ generateRanges(for: sampleString, by: 32)
72-
+ generateRanges(for: sampleString, by: 64)
73-
+ generateRanges(for: sampleString, by: 128)
74-
+ generateRanges(for: sampleString, by: 256)
75-
+ generateRanges(for: sampleString, by: 512))
92+
let mixedRanges = (
93+
generateRanges(for: mixedString, by: 1)
94+
+ generateRanges(for: mixedString, by: 2)
95+
+ generateRanges(for: mixedString, by: 4)
96+
+ generateRanges(for: mixedString, by: 8)
97+
+ generateRanges(for: mixedString, by: 16)
98+
+ generateRanges(for: mixedString, by: 32)
99+
+ generateRanges(for: mixedString, by: 64)
100+
+ generateRanges(for: mixedString, by: 128)
101+
+ generateRanges(for: mixedString, by: 256)
102+
+ generateRanges(for: mixedString, by: 512))
103+
104+
let asciiString = #"""
105+
Swift is a high-performance system programming language. It has a clean
106+
and modern syntax, offers seamless access to existing C and Objective-C code
107+
and frameworks, and is memory safe by default.
108+
109+
Although inspired by Objective-C and many other languages, Swift is not itself
110+
a C-derived language. As a complete and independent language, Swift packages
111+
core features like flow control, data structures, and functions, with
112+
high-level constructs like objects, protocols, closures, and generics. Swift
113+
embraces modules, eliminating the need for headers and the code duplication
114+
they entail.
115+
"""#
116+
117+
let asciiRanges = (
118+
generateRanges(for: asciiString, by: 1)
119+
+ generateRanges(for: asciiString, by: 2)
120+
+ generateRanges(for: asciiString, by: 4)
121+
+ generateRanges(for: asciiString, by: 8)
122+
+ generateRanges(for: asciiString, by: 16)
123+
+ generateRanges(for: asciiString, by: 32)
124+
+ generateRanges(for: asciiString, by: 64)
125+
+ generateRanges(for: asciiString, by: 128)
126+
+ generateRanges(for: asciiString, by: 256)
127+
+ generateRanges(for: asciiString, by: 512))
76128

77129
func generateRanges(for string: String, by step: Int) -> [Range<String.Index>] {
78130
var remaining = step

0 commit comments

Comments
 (0)