Time Profiler makes code run _much_ faster. What's going on?

This is a very strange Heisenbug - I'd love to hear any insights.

I have been using the swift colour picker https://github.com/jdstmporter/ColourWheel

On my iPad (iPad Air 2 Model A1566) it takes about 2 seconds for the code to generate the colour wheel.
It's running through and calculating pixel by pixel to create a bitmap picker.

This seemed kinda slow, so I though I'd fire up the time profiler and see if there are any obvious optimisations.

Here is where it gets weird.

With the profiler running, it only takes about 0.4 seconds

I expect the profiller to slow things down, but here it is speeding it up by a factor of 5.
What could possibly be going on?

My sample code is here

it's essentially just opening the Colour wheel with a simple timer:

static func pickColour(colour:UIColor, from:UIViewController){

let time = Date()

let picker = ColourPickerVC.controller
picker.color = colour

from.present(picker, animated: false, completion: {
    let done = Date()
    let timeTaken = done.timeIntervalSince(time)
    print("Took: \(timeTaken)")
    let alertController = UIAlertController(title: "Time", message: "\(timeTaken)", preferredStyle: .alert)
    picker.present(alertController, animated: true, completion: nil)

any ideas?

thank you

Are you perhaps running in Debug, but doing your profiling in Release configuration?

Screen Shot 2020-02-17 at 1.55.51 PM


yup - that was it.

No mystery then. Thank you.

1 Like