Created
June 6, 2022 11:18
-
-
Save kot331107/c391e54d7960944936bedef29297ece2 to your computer and use it in GitHub Desktop.
simple function to measure time of execution of anything. it's pretty enough to measure some simple things.
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
// | |
// main.swift | |
// swift challenges | |
// | |
// Created by Filipp Mikheev on 06.06.22. | |
// | |
func measureTime(block : (() -> Void)) { | |
let start = DispatchTime.now() | |
block() | |
let end = DispatchTime.now() | |
let totalNanosec = end.uptimeNanoseconds - start.uptimeNanoseconds | |
let timeInterval = Double(totalNanosec) / 1_000_000_000 | |
print("Time: \(timeInterval) seconds") | |
} | |
// USAGE | |
measureTime { | |
// Do your stuff here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment