我有下面的代码行,我需要测试它们的性能标准。但是不幸的是,Apple Document并不能帮助您对此有一个清晰的了解。
func addStrings() {
let maxCount = 100000
var array:Array<String> = Array()
for _ in 0..<maxCount {
array.append("Test")
}
}
下面列出了性能测试用例代码。
func testPerformanceExample() throws {
// This is an example of a performance test case.
let strings = StringsCreator()
self.measure {
// Put the code you want to measure the time of here.
strings.addStrings()
}
}
从结果看来,第一个值是平均值(0.0611s)的21.3%增长。但是其余属性的含义是什么,以及如何将它们设置(基准和最大STD开发)为可接受的标准。
它如何计算结果好88%,什么是+/- 8%?
要建立基线,请运行测试。时间信息已合并。
从此以后,每后续次运行测试,如果与基线的偏差太大,则失败。