Last active
June 3, 2021 01:06
-
-
Save kyungpyoda/02c2ea13b23cd6b1d31712032ba093b4 to your computer and use it in GitHub Desktop.
[Swift] Measuring execution time by using Date object
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 characters
| // | |
| // measure.swift | |
| // | |
| // Created by 홍경표 on 2021/05/31. | |
| // | |
| import Foundation | |
| final class Util { | |
| class func measure(_ description: String = "", _ function: () -> ()) { | |
| let start = Date() | |
| function() | |
| let end = Date() | |
| let description = description.isEmpty ? "" : "[\(description)] " | |
| print("\(description)Execution Time:", end.timeIntervalSince(start)) | |
| } | |
| } | |
| /* | |
| var randoms = (1...100000).map { _ in Int.random(in: 1...1000) } | |
| Util.measure { | |
| randoms.sort() | |
| } | |
| // let hugeStr = "..." | |
| Util.measure("Split") { | |
| _ = hugeStr.split(separator: " ") | |
| } | |
| Util.measure("Components") { | |
| _ = hugeStr.components(separatedBy: " ") | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.