i use NSLog many times,and i know that it has a delay time . my app has a delay time ,and i wonder if many logs can create that.
for example, if i have this code :
samplerTimer = [NSTimer scheduledTimerWithTimeInterval: 0.001f target: self selector: @selector(CheckData) userInfo: nil repeats: YES];
NSLog(@"%f",tmp);
the timer is calling a function each 1ms,and it works great, but my concern is that the log takes more time so the timer routine kind of change. i use hardware,so mseconds are important.
i am trying to understand,what exactly happen during nslog? the system is sleeping? other things are don开发者_运维知识库e in parallel ? how much time exactly does it take ?
NSLog()
writes to the standard output or error using printf
. It will also cause a flush, meaning that the program blocks until the output has been sent to the OS. This is slow.
Removing the NSLog()
statements will speed things up a lot. The easiest way to turn all logging off, is adding:
#define NSLog(...) 0
in your prefix header (the .pch
file), below the framework includes. Or you could add this line in the files you want to silence. If effectively replaces all NSLog()
statements with 0
, which does nothing.
精彩评论