2015-12-11 Measuring startup time

The startup time of your app is determined by a bunch of things, but one that you can easily and directly influence, is the time spent in your AppDelegate's function didFinishLaunchingWithOptions. You may have put a number of things in there, and if you want to find out which step is taking up all that time, it's not always useful to fire up Instruments. A simple way is to just dump a bunch of logging statements.

Paste the following code at the top of the AppDelegate.swift file.

	var logTimer: CFTimeInterval = -1.0
	var logStep = 1
	func logAppProgressInit() {
		logTimer = CACurrentMediaTime()
	}
	func logAppProgress() {
		let stepTime = CACurrentMediaTime() - logTimer
		NSLog("Step %d took %.3f seconds", logStep, stepTime)
		logStep++
		logTimer = CACurrentMediaTime()
	}

Then paste the following line at the top of your didFinishLaunchingWithOptions:

	logAppProgressInit()

And the following line after each (functionally meaningful) line of code in didFinishLaunchingWithOptions:

	logAppProgress()

This code is just for a quick round of debugging, and must be removed afterwards. NSLog itself is slow and wasteful in this phase.