Skip to content

Commit f48f291

Browse files
authored
Merge pull request #3560 from swiftwasm/main
[pull] swiftwasm from main
2 parents 696a503 + af1706e commit f48f291

File tree

233 files changed

+4116
-3442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+4116
-3442
lines changed

benchmark/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ set(SWIFT_BENCH_MODULES
5959
single-source/CharacterProperties
6060
single-source/Chars
6161
single-source/ClassArrayGetter
62-
single-source/Codable
62+
single-source/CodableTest
6363
single-source/Combos
6464
single-source/DataBenchmarks
6565
single-source/DeadArray
@@ -76,7 +76,7 @@ set(SWIFT_BENCH_MODULES
7676
single-source/DictionaryCopy
7777
single-source/DictionaryGroup
7878
single-source/DictionaryKeysContains
79-
single-source/DictionaryLiteral
79+
single-source/DictionaryLiteralTest
8080
single-source/DictionaryOfAnyHashableStrings
8181
single-source/DictionaryRemove
8282
single-source/DictionarySubscriptDefault
@@ -112,11 +112,11 @@ set(SWIFT_BENCH_MODULES
112112
single-source/LuhnAlgoLazy
113113
single-source/MapReduce
114114
single-source/Memset
115-
single-source/Mirror
115+
single-source/MirrorTest
116116
single-source/MonteCarloE
117117
single-source/MonteCarloPi
118118
single-source/NSDictionaryCastToSwift
119-
single-source/NSError
119+
single-source/NSErrorTest
120120
single-source/NSStringConversion
121121
single-source/NibbleSort
122122
single-source/NIOChannelPipeline
@@ -143,7 +143,7 @@ set(SWIFT_BENCH_MODULES
143143
single-source/ProtocolConformance
144144
single-source/ProtocolDispatch
145145
single-source/ProtocolDispatch2
146-
single-source/Queue
146+
single-source/QueueTest
147147
single-source/RC4
148148
single-source/RGBHistogram
149149
single-source/Radix2CooleyTukey
@@ -186,7 +186,7 @@ set(SWIFT_BENCH_MODULES
186186
single-source/StringSwitch
187187
single-source/StringTests
188188
single-source/StringWalk
189-
single-source/Substring
189+
single-source/SubstringTest
190190
single-source/Suffix
191191
single-source/SuperChars
192192
single-source/TwoSum

benchmark/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,16 +313,18 @@ If needed you can multiply N by a fixed amount (e.g. `1...100*N`) to achieve thi
313313
// rdar://problem/00000000
314314
import TestsUtils
315315
316-
public let YourTestName = BenchmarkInfo(
317-
name: "YourTestName",
318-
runFunction: run_YourTestName,
319-
tags: [.regression])
316+
public let benchmarks = [
317+
BenchmarkInfo(
318+
name: "YourTestName",
319+
runFunction: run_YourTestName,
320+
tags: [.regression])
321+
]
320322
321323
@inline(never)
322-
public func run_YourTestName(N: Int) {
324+
public func run_YourTestName(n: Int) {
323325
# Declare variables
324326
325-
for i in 1...N {
327+
for i in 1...n {
326328
# Perform work
327329
328330
# Verify work was done; break otherwise

benchmark/cxx-source/CreateObjects.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
import TestsUtils
1717
import CxxCreateObjects
1818

19-
public let CreateObjects = BenchmarkInfo(
20-
name: "CreateObjects",
21-
runFunction: run_CreateObjects,
22-
tags: [.validation, .bridging])
19+
public let benchmarks = [
20+
BenchmarkInfo(
21+
name: "CreateObjects",
22+
runFunction: run_CreateObjects,
23+
tags: [.validation, .bridging])
24+
]
2325

2426
@inline(never)
25-
public func run_CreateObjects(_ N: Int) {
26-
for i in 0...(N * 10_000) {
27+
public func run_CreateObjects(_ n: Int) {
28+
for i in 0...(n * 10_000) {
2729
let x = Int32(i)
2830
let f = CxxLoadableIntWrapper(value: x)
2931
blackHole(f)

benchmark/multi-source/PrimsSplit/Prims.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PriorityQueue {
7070
while (ind != 0) {
7171
let p = getParentIndex(ind)
7272
if heap[p].cost > c {
73-
Swap(p, with: ind)
73+
swap(p, with: ind)
7474
ind = p
7575
} else {
7676
break
@@ -83,7 +83,7 @@ class PriorityQueue {
8383
if (heap.isEmpty) {
8484
return nil
8585
}
86-
Swap(0, with:heap.count-1)
86+
swap(0, with:heap.count-1)
8787
let r = heap.removeLast()
8888
graphIndexToHeapIndexMap[r.to] = nil
8989
bubbleDown(0)
@@ -111,21 +111,21 @@ class PriorityQueue {
111111
if (heap[ind].cost <= heap[min].cost) {
112112
break
113113
}
114-
Swap(ind, with: min)
114+
swap(ind, with: min)
115115
ind = min
116116
}
117117
}
118118

119119
// Swaps elements I and J in the heap and correspondingly updates
120120
// graphIndexToHeapIndexMap.
121-
func Swap(_ i: Int, with j : Int) {
121+
func swap(_ i: Int, with j : Int) {
122122
if (i == j) {
123123
return
124124
}
125125
(heap[i], heap[j]) = (heap[j], heap[i])
126-
let (I, J) = (heap[i].to, heap[j].to)
127-
(graphIndexToHeapIndexMap[I], graphIndexToHeapIndexMap[J]) =
128-
(graphIndexToHeapIndexMap[J], graphIndexToHeapIndexMap[I])
126+
let (i2, j2) = (heap[i].to, heap[j].to)
127+
(graphIndexToHeapIndexMap[i2], graphIndexToHeapIndexMap[j2]) =
128+
(graphIndexToHeapIndexMap[j2], graphIndexToHeapIndexMap[i2])
129129
}
130130

131131
// Dumps the heap.
@@ -182,7 +182,7 @@ extension Edge : Hashable {
182182
}
183183
}
184184

185-
func Prims(_ graph : Array<GraphNode>, _ fun : (Int, Int) -> Double) -> Array<Int?> {
185+
func prims(_ graph : Array<GraphNode>, _ fun : (Int, Int) -> Double) -> Array<Int?> {
186186
var treeEdges = Array<Int?>(repeating:nil, count:graph.count)
187187

188188
let queue = PriorityQueue(Num:graph.count)

benchmark/multi-source/PrimsSplit/Prims_main.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212

1313
import TestsUtils
1414

15-
public let PrimsSplit = BenchmarkInfo(
16-
name: "PrimsSplit",
17-
runFunction: run_PrimsSplit,
18-
tags: [.validation, .algorithm],
19-
legacyFactor: 5)
15+
public let benchmarks = [
16+
BenchmarkInfo(
17+
name: "PrimsSplit",
18+
runFunction: run_PrimsSplit,
19+
tags: [.validation, .algorithm],
20+
legacyFactor: 5)
21+
]
2022

2123
@inline(never)
22-
public func run_PrimsSplit(_ N: Int) {
23-
for _ in 1...N {
24+
public func run_PrimsSplit(_ n: Int) {
25+
for _ in 1...n {
2426
let nodes : [Int] = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
2527
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
2628
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
@@ -547,7 +549,7 @@ public func run_PrimsSplit(_ N: Int) {
547549
}
548550

549551
// Find spanning tree
550-
let treeEdges = Prims(graph, { (start: Int, end: Int) in
552+
let treeEdges = prims(graph, { (start: Int, end: Int) in
551553
return map[Edge(start: start, end: end)]!
552554
})
553555

@@ -556,6 +558,6 @@ public func run_PrimsSplit(_ N: Int) {
556558
for i in 1..<treeEdges.count {
557559
if let n = treeEdges[i] { cost += map[Edge(start: n, end: i)]! }
558560
}
559-
CheckResults(Int(cost) == 49324)
561+
check(Int(cost) == 49324)
560562
}
561563
}

benchmark/scripts/Template.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public let {name} = [
1717
]
1818

1919
@inline(never)
20-
public func run_{name}(N: Int) {{
20+
public func run_{name}(n: Int) {{
2121
// TODO
2222
}}

benchmark/single-source/Ackermann.swift

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -14,38 +14,39 @@
1414
// for performance measuring.
1515
import TestsUtils
1616

17-
public let Ackermann = BenchmarkInfo(
18-
name: "Ackermann",
19-
runFunction: run_Ackermann,
20-
tags: [.algorithm])
17+
public let benchmarks =
18+
BenchmarkInfo(
19+
name: "Ackermann",
20+
runFunction: run_Ackermann,
21+
tags: [.algorithm])
2122

22-
func ackermann(_ M: Int, _ N : Int) -> Int {
23-
if (M == 0) { return N + 1 }
24-
if (N == 0) { return ackermann(M - 1, 1) }
25-
return ackermann(M - 1, ackermann(M, N - 1))
23+
func _ackermann(_ m: Int, _ n : Int) -> Int {
24+
if (m == 0) { return n + 1 }
25+
if (n == 0) { return _ackermann(m - 1, 1) }
26+
return _ackermann(m - 1, _ackermann(m, n - 1))
2627
}
2728

2829
@inline(never)
29-
func Ackermann(_ M: Int, _ N : Int) -> Int {
30+
func ackermann(_ m: Int, _ n : Int) -> Int {
3031
// This if prevents optimizer from computing return value of Ackermann(3,9)
3132
// at compile time.
32-
if False() { return 0 }
33-
if (M == 0) { return N + 1 }
34-
if (N == 0) { return ackermann(M - 1, 1) }
35-
return ackermann(M - 1, ackermann(M, N - 1))
33+
if getFalse() { return 0 }
34+
if (m == 0) { return n + 1 }
35+
if (n == 0) { return _ackermann(m - 1, 1) }
36+
return _ackermann(m - 1, _ackermann(m, n - 1))
3637
}
3738

3839
let ref_result = [5, 13, 29, 61, 125, 253, 509, 1021, 2045, 4093, 8189, 16381, 32765, 65533, 131069]
3940

4041
@inline(never)
41-
public func run_Ackermann(_ N: Int) {
42+
public func run_Ackermann(_ n: Int) {
4243
let (m, n) = (3, 6)
4344
var result = 0
44-
for _ in 1...N {
45-
result = Ackermann(m, n)
45+
for _ in 1...n {
46+
result = ackermann(m, n)
4647
if result != ref_result[n] {
4748
break
4849
}
4950
}
50-
CheckResults(result == ref_result[n])
51+
check(result == ref_result[n])
5152
}

benchmark/single-source/AngryPhonebook.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -16,7 +16,7 @@ import TestsUtils
1616

1717
let t: [BenchmarkCategory] = [.validation, .api, .String]
1818

19-
public let AngryPhonebook = [
19+
public let benchmarks = [
2020
BenchmarkInfo(
2121
name: "AngryPhonebook",
2222
runFunction: run_AngryPhonebook,
@@ -76,9 +76,9 @@ let words = [
7676
"Nicholas", "Eric", "Stephen", "Jacob", "Larry", "Frank"]
7777

7878
@inline(never)
79-
public func run_AngryPhonebook(_ N: Int) {
79+
public func run_AngryPhonebook(_ n: Int) {
8080
// Permute the names.
81-
for _ in 1...N {
81+
for _ in 1...n {
8282
for firstname in words {
8383
for lastname in words {
8484
_ = (firstname.uppercased(), lastname.lowercased())
@@ -132,10 +132,10 @@ let longArmenian = phonebook(armenian)
132132
let longCyrillic = phonebook(cyrillic)
133133

134134
@inline(never)
135-
public func angryPhonebook(_ N: Int, _ names: [String]) {
135+
public func angryPhonebook(_ n: Int, _ names: [String]) {
136136
assert(names.count == 20)
137137
// Permute the names.
138-
for _ in 1...N {
138+
for _ in 1...n {
139139
for firstname in names {
140140
for lastname in names {
141141
blackHole((firstname.uppercased(), lastname.lowercased()))
@@ -145,8 +145,8 @@ public func angryPhonebook(_ N: Int, _ names: [String]) {
145145
}
146146

147147
@inline(never)
148-
public func angryPhonebook(_ N: Int, precomposed names: String) {
149-
for _ in 1...N {
148+
public func angryPhonebook(_ n: Int, precomposed names: String) {
149+
for _ in 1...n {
150150
blackHole((names.uppercased(), names.lowercased()))
151151
}
152152
}

benchmark/single-source/AnyHashableWithAClass.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -22,12 +22,13 @@ import TestsUtils
2222
// 11% _swift_stdlib_makeAnyHashableUpcastingToHashableBaseType
2323
// 16% _swift_retain_[n]
2424
// 5% swift_conformsToProtocol
25-
public let AnyHashableWithAClass = BenchmarkInfo(
26-
name: "AnyHashableWithAClass",
27-
runFunction: run_AnyHashableWithAClass,
28-
tags: [.abstraction, .runtime, .cpubench],
29-
legacyFactor: 500
30-
)
25+
public let benchmarks =
26+
BenchmarkInfo(
27+
name: "AnyHashableWithAClass",
28+
runFunction: run_AnyHashableWithAClass,
29+
tags: [.abstraction, .runtime, .cpubench],
30+
legacyFactor: 500
31+
)
3132

3233
class TestHashableBase : Hashable {
3334
var value: Int
@@ -54,9 +55,9 @@ class TestHashableDerived4 : TestHashableDerived3 {}
5455
class TestHashableDerived5 : TestHashableDerived4 {}
5556

5657
@inline(never)
57-
public func run_AnyHashableWithAClass(_ N: Int) {
58+
public func run_AnyHashableWithAClass(_ n: Int) {
5859
let c = TestHashableDerived5(10)
59-
for _ in 0...(N*1000) {
60+
for _ in 0...(n*1000) {
6061
_ = AnyHashable(c)
6162
}
6263
}

0 commit comments

Comments
 (0)