I have mex code that I call from my matlab scripts. To debug the code, I had put a lot of mexPrintf statements, but for timing purposes now I don’t want any I/O taking place in my mex code call (since I/O takes a lot of time). What’s the easiest and best way to suppress the mexPrintf calls in my code, such that those statements are not executed at all, without having to delete/comment out those statements? (I don’t want to delete/comment out those statements and recompile my mex code because I may need these debug statements later on, and I don’t want to keep going through this iteration of modifying and building my code again and again).
Is there any compiler switch that can do the trick? or some preprocessor statement?
Thanks!
You can not turn
mexPrintfoff. You need to modify your code. Define e.g.DEBUGflag to decide, when you want to print things, and when not. For example, with normalprintffunctionNothing is printed if you run it now. But if you uncomment the
#define DEBUGstatement, you get 5 printed.Alternatively, you can embrace all
mexPrintfcalls in such clauses:Again, nothing will be printed if
DEBUGis not defined. But that is much more work.You can also do a similar thing without recompiling your mex file by using a normal
ifstatement and pass averboseparameter to the mex file. However, this will still have some impact on performance if you execute theifstatement too often. So go for theDEBUGmore – that is the standard way to do it.