有没有办法在不使用 Xcode 11 在 iPhone 上构建 UI 的情况下测量 Swift 的性能? [英] is there a way to measure Swift's performance without building UI on iPhone with Xcode 11?

查看:23
本文介绍了有没有办法在不使用 Xcode 11 在 iPhone 上构建 UI 的情况下测量 Swift 的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测量不同 swift 库的性能,而无需在 iPhone 上编写 UI.有许多 Swift/UI 示例,它们通常是多线程的.因此,如果可能的话,我想衡量的是没有 gui 开销的原始性能.例如,我们可以将输出打印到调试器中的 Xcode 11 控制台窗口中.你能指点我在哪里可以找到这样的示例代码吗?我将不胜感激.

I need to measure performance of different swift libraries without writing UI on iPhone. There are many examples of Swift/UI examples that are normally, multi-threaded in nature. So what I want to measure is raw performance without gui overhead, if possible. And the output can we printed into the Xcode 11 console window in debugger, for example. Could you please kindly point me where I could find such sample code ? I would greatly appreciate the help.

推荐答案

这是一个如何测量数字和的时间的例子

This is an example of how to measure the time of a sum of numbers

let numbersArray = [1,2,3,4,5,6,7,8,9,1,2,3,4,5,6]

func showBenchmarkTime(title:String, operation:()->()) {

    let startTime = CFAbsoluteTimeGetCurrent()

    operation()

    let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime

    print("Time elapsed for \(title): \(timeElapsed) s.")
}

showBenchmarkTime(title: "sum an array of numbers") {

    print(numbersArray.reduce(0, +))
}

这篇关于有没有办法在不使用 Xcode 11 在 iPhone 上构建 UI 的情况下测量 Swift 的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆