0

Is there a way to tell how long a NSOperation has been executing?

 for (NSOperation *operation in [self.operationQueue operations]) {
     // how to tell how long the operation has been executing?
 }
ohho
  • 50,879
  • 75
  • 256
  • 383

1 Answers1

1

Make two variables, NSTimeInterval.

NSTimeInterval t1, t2;

When the operation starts you run :

t1 = NSTimeIntervalSince1970;

and when it finishes

t2 = NSTimeIntervalSince1970;

Then you simply do

NSTimeInterval t3 = t2 -t1;

No you know how many seconds this did run. This is crude and perhaps there are better ways to get exact numbers, but I would then suggest you use a profiler like Instruments.

But this is a good measure as it is quite simple and does not take away any cpu power, like a profiler would do.

I would also suggest searching standard C libraries for some cpu ticks or something close to that.

Enjoy.

Trausti Thor
  • 3,722
  • 31
  • 41