|
| 1 | +//===--- CxxSetToCollection.swift -----------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2012 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +// This is a benchmark that tracks how quickly Swift can convert a C++ set |
| 14 | +// to a Swift collection. |
| 15 | + |
| 16 | +import TestsUtils |
| 17 | + |
| 18 | +#if SWIFT_PACKAGE |
| 19 | +// FIXME: Needs fix for https://github.com/apple/swift/issues/61547. |
| 20 | + |
| 21 | +public let benchmarks = [BenchmarkInfo]() |
| 22 | + |
| 23 | +#else |
| 24 | + |
| 25 | +import CxxStdlibPerformance |
| 26 | +import Cxx |
| 27 | + |
| 28 | +public let benchmarks = [ |
| 29 | + BenchmarkInfo( |
| 30 | + name: "CxxSetU32.to.Array", |
| 31 | + runFunction: run_CxxSetOfU32_to_Array, |
| 32 | + tags: [.validation, .bridging, .cxxInterop], |
| 33 | + setUpFunction: makeSetOnce), |
| 34 | + BenchmarkInfo( |
| 35 | + name: "CxxSetU32.to.Set", |
| 36 | + runFunction: run_CxxSetOfU32_to_Set, |
| 37 | + tags: [.validation, .bridging, .cxxInterop], |
| 38 | + setUpFunction: makeSetOnce), |
| 39 | +] |
| 40 | + |
| 41 | +func makeSetOnce() { |
| 42 | + initSet(setSize) |
| 43 | +} |
| 44 | + |
| 45 | +let setSize = 1_000 |
| 46 | + |
| 47 | +@inline(never) |
| 48 | +public func run_CxxSetOfU32_to_Array(_ n: Int) { |
| 49 | + for _ in 0..<n { |
| 50 | + blackHole(Array(set)) |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +@inline(never) |
| 55 | +public func run_CxxSetOfU32_to_Set(_ n: Int) { |
| 56 | + for _ in 0..<n { |
| 57 | + blackHole(Set(set)) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +#endif |
0 commit comments