JoshDG
JoshDG

Reputation: 3931

Will NSLog slow my app?

I have a lot of NSLog's in my app - some of which often print large amounts of data - ie results of a search. Will this make an appreciable difference in the speed of my app?

I'm not familiar with macros - would someone be able to suggest one that would enable/disable all NSLogs?

Upvotes: 9

Views: 2350

Answers (4)

Arek Holko
Arek Holko

Reputation: 9006

You should use something like DLog from MY CURRENT PREFIX.PCH FILE. It'll disable logging in the Release build. This is a great explanation of why you shouldn't keep NSLog's in the Release build.

Upvotes: 4

Asad Khan
Asad Khan

Reputation: 11889

YES!! too many NSLOgs will definitely slow your app.

As a best practice I usually add this in my .pch(pre compiled header file)

#ifdef DEBUG
#define DebugLog(f, ...) NSLog(f, ## __VA_ARGS__)
#else
#define DebugLog(f, ...)
#endif

just enabled DEBUG in your preprocessor macro in build settings for debug target. Use DebugLog instead of NSLog().

Your distribution/release will not have DEBUG defined. So your app wont print anything in the log for distributed app.

Upvotes: 0

ipinak
ipinak

Reputation: 6039

If your app is for production try to minimize them. Keep only the ones useful for errors or possible warnings. If you used them for helping you debug, then I advise you to remove them.

Upvotes: 1

pNre
pNre

Reputation: 5376

Yes NSLog could make your app slower because of its synchronism. To toggle all NSLog

#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#else 
#define NSLog(...)
#endif

Upvotes: 16

Related Questions