mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Create Pack Specialisation pass
This commit is contained in:
@@ -139,6 +139,7 @@ set(SWIFT_BENCH_MODULES
|
||||
single-source/ObserverUnappliedMethod
|
||||
single-source/OpaqueConsumingUsers
|
||||
single-source/OpenClose
|
||||
single-source/ParameterPacks
|
||||
single-source/Phonebook
|
||||
single-source/PointerArithmetics
|
||||
single-source/PolymorphicCalls
|
||||
|
||||
53
benchmark/single-source/ParameterPacks.swift
Normal file
53
benchmark/single-source/ParameterPacks.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
//===--- ParameterPacks.swift ---------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift.org open source project
|
||||
//
|
||||
// Copyright (c) 2025 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This benchmark serves to test the overhead of
|
||||
|
||||
import TestsUtils
|
||||
|
||||
public let benchmarks = [
|
||||
BenchmarkInfo(
|
||||
name: "ParameterPacks.VariadicFibonacci",
|
||||
runFunction: run_ParameterPacksVariadicFibonacci,
|
||||
tags: [.validation])
|
||||
]
|
||||
|
||||
@inline(never)
|
||||
func numericLoop<each T: BinaryInteger>(xs: repeat each T) -> (repeat each T) {
|
||||
return
|
||||
(repeat { x in
|
||||
// Recursive "Fibonacci" function prevents inlining
|
||||
if x <= 1 {
|
||||
return x
|
||||
} else {
|
||||
let (a, b) = numericLoop(xs: x - 1, x - 2)
|
||||
return a + b
|
||||
}
|
||||
}(each xs)
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
let expectedResult = (610, 987, 1597)
|
||||
|
||||
@inline(never)
|
||||
public func run_ParameterPacksVariadicFibonacci(_ n: Int) {
|
||||
var result = (0, 0, 0)
|
||||
for _ in 1...n {
|
||||
result = numericLoop(xs: 15, 16, 17)
|
||||
if result != expectedResult {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
check(result == expectedResult)
|
||||
}
|
||||
@@ -143,6 +143,7 @@ import ObserverPartiallyAppliedMethod
|
||||
import ObserverUnappliedMethod
|
||||
import OpaqueConsumingUsers
|
||||
import OpenClose
|
||||
import ParameterPacks
|
||||
import Phonebook
|
||||
import PointerArithmetics
|
||||
import PolymorphicCalls
|
||||
@@ -343,6 +344,7 @@ register(ObserverPartiallyAppliedMethod.benchmarks)
|
||||
register(ObserverUnappliedMethod.benchmarks)
|
||||
register(OpaqueConsumingUsers.benchmarks)
|
||||
register(OpenClose.benchmarks)
|
||||
register(ParameterPacks.benchmarks)
|
||||
register(Phonebook.benchmarks)
|
||||
register(PointerArithmetics.benchmarks)
|
||||
register(PolymorphicCalls.benchmarks)
|
||||
|
||||
Reference in New Issue
Block a user