문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top