Merge pull request #21905 from gottesmm/pr-e4aa69192289f84c89c0ffdec8febf6e15f0558f
[benchmark] Add autoreleasepools to the Codable tests to prevent "lea…
diff --git a/benchmark/single-source/Codable.swift b/benchmark/single-source/Codable.swift
index b0c451a..1729a7a 100644
--- a/benchmark/single-source/Codable.swift
+++ b/benchmark/single-source/Codable.swift
@@ -107,17 +107,33 @@
JSONTester = CodablePerfTester(encoder: JSONEncoder(), decoder: JSONDecoder())
}
+#if !_runtime(_ObjC)
+// If we do not have an objc-runtime, then we do not have a definition for
+// autoreleasepool. Add in our own fake autoclosure for it that is inline
+// always. That should be able to be eaten through by the optimizer no problem.
+@inline(__always)
+public func autoreleasepool<Result>(
+ invoking body: () throws -> Result
+) rethrows -> Result {
+ return try body()
+}
+#endif
+
@inline(never)
public func run_JSONPerfEncode(_ N: Int) {
- for _ in 0 ..< N {
- JSONTester.encode()
+ autoreleasepool {
+ for _ in 0 ..< N {
+ JSONTester.encode()
+ }
}
}
@inline(never)
public func run_JSONPerfDecode(_ N: Int) {
- for _ in 0 ..< N {
- JSONTester.decode()
+ autoreleasepool {
+ for _ in 0 ..< N {
+ JSONTester.decode()
+ }
}
}
@@ -131,15 +147,19 @@
@inline(never)
public func run_PlistPerfEncode(_ N: Int) {
- for _ in 0 ..< N {
- plistTester.encode()
+ autoreleasepool {
+ for _ in 0 ..< N {
+ plistTester.encode()
+ }
}
}
@inline(never)
public func run_PlistPerfDecode(_ N: Int) {
- for _ in 0 ..< N {
- plistTester.decode()
+ autoreleasepool {
+ for _ in 0 ..< N {
+ plistTester.decode()
+ }
}
}