如何从 Swift 呼叫 dispatch_benchmark

How to call dispatch_benchmark from Swift

dispatch_benchmark()GCD 中未导出的函数。但是,您可以通过在代码中声明它来在 Objective C 中调用它:

uint64_t dispatch_benchmark(size_t count, void (^block)(void));

我该怎么做Swift

只需将声明放入桥接中即可 header:

@import Foundation;

uint64_t dispatch_benchmark(size_t count, void (^block)(void));

这将使该功能在 Swift 中自动可用。