开发者

iPhone/iPad : Does having many NSLog() calls affect app preformance or memory?

I would like to know if having many NSLog() calls affects app performance or memory. Does anyone know about such thing?

I want to put an NSLog() call in every function in my app (wh开发者_C百科ich is a lot) so that I can see crash logs after and trace problems.

Thanks.


Yes. So I define this in my pch file.

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#   define DLog(...)
#endif

// ALog always displays output regardless of the DEBUG setting
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

Instead of using NSLog, I use DLog and ALog.

(Note or copyrights: I got this code long long ago from some other SO post which I don't remember. Pasting it again from my snippet library)


Another easy solution to 'undefine' NSLog

In .pch file:

#ifndef DEBUG
#define NSLog(...) /* */
#endif


Yes, it slows down the performance, especially if the function is supposed to take very short time, the NSLog (which is an I/O process) will make it take more time than expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜