I have an application that does a bunch of small computations, mostly Table management, and logic around loops. It takes seconds to execute. However, when I turn on debug (a variable I set for varying levels of output), which is often necessary to see how certain decisions were made, it can take 5 minutes to 15 minutes to execute. This is less than ideal, as I'm using this to aid live events in realtime.
Here, the debug function executed 9625 times in a recent execution. The function is as follows:
showDebug[debug_,thisDebug_,content_]:=
Module[{},
howManyDebugs++;
If[debug >= thisDebug,
Print[content];
]
];
Content can consist of a simple one-line output or a stringified table.
Per answer below, I've upgraded the code to use
showDebug[debug_,thisDebug_,content_]:=
Module[{},
howManyDebugs++;
If[debug >= thisDebug,
WriteString["stdout",content,"\n"];
]
];
Is there a more efficient way to capture this data than outputting to the screen?
After making the change detailed above, I've experienced a roughly 50% decrease in execution time.
Sow
andReap
. $\endgroup$