Strip you NSLog()s automatically

November 12, 2009

The folks over at the iQuit blog have mentioned that disabling NSLog calls in your iPhone code results in a huge performance improvement.  Having done so myself, I can firmly attest to that.  An easy way to disable NSLog calls globally is to put a few lines of macros in your project’s precompiled header (.pch) file:

//force NSLog disable
//uncomment to force NSLog disabling no matter what
//note: you will need to add the DEBUG symbol to your
//  project's preprocessor flags setting
#if !defined(DEBUG) || defined(FORCE_NSLOG_DISABLE)
//variadic MACROS may be gcc only
#	define NSLog(...) ;

This will replace all NSLog calls to no-ops, which is of course much cheaper than printing to stdout.

Leave a Reply