Sunday, October 11, 2009

iPhone dev Stupidity 68: Handcraft Profiler

Learned from here:


#include <mach/mach_time.h>




#define START_PROFILE(name)\


{\


const char * msg = name;\


mach_timebase_info_data_t info;\


mach_timebase_info(&info);\


uint64_t start = mach_absolute_time();




#define END_PROFILE\


uint64_t duration = mach_absolute_time() - start;\


duration *= info.numer;\


duration /= info.denom;\


NSLog(@"%s took %lld nanoseconds!", msg, duration);\


}



To use:

START_PROFILE("dude");
// some code here
// ...
END_PROFILE;

No comments: