Last active
November 4, 2022 21:29
Revisions
-
ncreated revised this gist
Nov 4, 2022 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ extension XCTestCase { func benchmark(_ label: String, iterations: Int = 100, block: () throws -> Void) rethrows { var measures: [TimeInterval] = [] let warmUp = iterations / 10 for i in (0..<iterations) { let start = Date() try block() if i >= warmUp { // only measure after it is warmed-up let stop = Date() measures.append(stop.timeIntervalSince(start)) } -
ncreated created this gist
Nov 4, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ extension XCTestCase { func benchmark(_ label: String, block: () -> Void) { var measures: [TimeInterval] = [] for i in (0..<1_010) { let start = Date() block() if i >= 10 { // only measure after it is warmed-up let stop = Date() measures.append(stop.timeIntervalSince(start)) } } let sum = measures.reduce(0, +) let avg = sum / Double(measures.count) print("⭐️ AVG in \(label): \(avg * 1_000) ms") } }