Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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 :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top