当谈到NSAutoreleasePool时,人们总是说NSRunLoop。我可以找出一个runloop循环有多长?
#include <Foundation/Foundation.h>
#include <time.h>
clock_t entryTM = 0;
clock_t exitTM = 0;
void callback(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
{
exitTM = clock();
NSLog(@"Total: %.5fs", (exitTM - entryTM) * 1.0/CLOCKS_PER_SEC);
entryTM = clock();
}
int main(int argc, char const *argv[])
{
CFRunLoopObserverRef observerRef = CFRunLoopObserverCreate(
kCFAllocatorDefault,
kCFRunLoopBeforeTimers,
true,
0,
callback,
NULL);
CFRunLoopAddObserver(
CFRunLoopGetCurrent(),
observerRef,
kCFRunLoopCommonModes);
if (CFRunLoopContainsObserver(CFRunLoopGetCurrent(),
observerRef,
kCFRunLoopCommonModes))
{
NSLog(@"Has observer!");
}
[NSTimer scheduledTimerWithTimeInterval: 1
target: nil
selector: @selector(print)
userInfo: nil
repeats: YES];
CFRunLoopRun();
return 0;
}