0

The following two functions does the same thing but the first one uses way more CPU time then the other one. I have learned this only from observing the Time Profiler in Instrument. (After digging in the call trees). I was wondering if there is a faster way to determine how much a function will cost. For example, without much background knowledge, I would not know by how much one function is faster than the other unless I profile the whole app and dig into the call trees, a maybe repeat a few times to confirm (sort of time consuming)

var dataLengh_kb: Int {
    return (UIImageJPEGRepresentation(self, 1.0)?.length)! / 1024
}

var dataLengh_kb : Int {
    return CGImageGetHeight(self.CGImage) * CGImageGetBytesPerRow(self.CGImage) / 1024
}
user172902
  • 3,541
  • 9
  • 32
  • 75
  • You can just count NSTimer before the function to after it finish to see, it's better for value one function than time profiler – Tj3n Sep 22 '16 at 09:29
  • How about you invert the call tree when you do profiling? This way at least you won't have to dig :) – Nailer Sep 22 '16 at 13:05

0 Answers0