Refer to this question below
How to log a method's execution time exactly in milliseconds?
And I convert the code to swift like this
//OBjective-C
//#define TICK NSDate *startTime = [NSDate date]
//#define TOCK NSLog(@"Time: %f", -[startTime timeIntervalSinceNow])
class AppDelegate: NSObject, NSApplicationDelegate {
var TIMER = NSDate()
@IBOutlet weak var window: NSWindow!
func TICK()
{
TIMER = NSDate()
}
func TOCK(){
println("\(-TIMER.timeIntervalSinceNow)")
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
TICK()
TOCK()
}
Timing in Swift : 3.40343e-05 while Objective-C : 0.000009 Why Swift is so slow?
Thank you.