1

I want to know the exact time consumed by a certain function running on iPad. For some reason I can't connect the iPad to the macbook while running the application (the USB is occupied by other device).

I had tried using clock(), like this

clock_t start = clock();

/* Do something here */

double executionTime = (double)(clock()-start) / CLOCKS_PER_SEC;

I have no idea why the value of executionTime will be 0. The difference of start time and end time is something like 1,000,000,000 (Calculated by myself). However I can't get the correct CLOCKS_PER_SEC(it changes every time), so I have no idea what the meaning of that number.

I read the post "ctime on iOS device not measuring time properly", but it does not help. Is there any way to fix the CLOCKS_PER_SEC? Or there's other way to measure the time.

Thank you

The value of CLK_TCK is 1,000,000. The whole program finishes with 5 seconds.

iOS Padawan
  • 418
  • 1
  • 5
  • 16

2 Answers2

3

executionTime is a double, not an int. You must use the %f format instead of %d for formatting.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • I just found that stupid mistake... I still can't get the correct time by using the old method. However, The Organizer works just fine! Thank you! – iOS Padawan Aug 19 '12 at 12:19
  • I'm glad that I could help. - If you think that I have answered the original question, you might consider to "accept" the answer. – Martin R Aug 19 '12 at 12:26
  • Oh! Sure! For those who still can't solve the problem with changing the format. Please check Martin R's comments of the question. – iOS Padawan Aug 19 '12 at 12:54
1

Check out the profiling utility that xcode offers.

There is more information here:

How to profile memory usage & performance with Instruments?

It is very powerful, and awesome :)

Community
  • 1
  • 1
ddoor
  • 5,819
  • 9
  • 34
  • 41
  • It seems that it's about measuring memory usage? – iOS Padawan Aug 19 '12 at 10:26
  • Yep, but you should be able to set it up for execution time. – ddoor Aug 19 '12 at 10:29
  • How would that help if the device can not be connected using the connector cable? – Till Aug 19 '12 at 10:38
  • Yea, you need the cable. Sorry just assumed you had it, then did a re-read :( Are you having any luck with it all? – ddoor Aug 19 '12 at 11:44
  • Thank you. It's fine, at least now I know there's a good tool when the cable is available. In current situation, the USB is used to connect an external device. In fact, the function I'm trying to measure is running on the external device, that's the reason the USB can't be used... – iOS Padawan Aug 19 '12 at 12:05