//===--- TaskLocalGet.swift -----------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2026 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // Measures cross-module TaskLocal.get() performance. import TestsUtils public var benchmarks: [BenchmarkInfo] { guard #available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) else { return [] } return [ BenchmarkInfo( name: "TaskLocalGet.Unbound", runFunction: run_TaskLocalGetUnbound, tags: [.concurrency] ), BenchmarkInfo( name: "TaskLocalGet.Bound", runFunction: run_TaskLocalGetBound, tags: [.concurrency] ), BenchmarkInfo( name: "TaskLocalGet.Bound.Nested", runFunction: run_TaskLocalGetBoundNested, tags: [.concurrency] ), ] } @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) private enum BenchTaskLocals { @TaskLocal static var value: Int = 0 @TaskLocal static var one: Int = 0 @TaskLocal static var two: Int = 0 @TaskLocal static var three: Int = 0 } // Read a task-local that has no binding (returns defaultValue). // This is the fast path — just a null check + return default. @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *) private func run_TaskLocalGetUnbound(_ n: Int) { for _ in 0..