I am writing a program, about a thousand lines, and I put some cout in the code. But the code is running very slow, so I noted that the problem is the cout inside the loops, they repeat many many times.
Then I changed the cout to output to file but then it was clear that something is going in a not desired way, the hdd led become flashing all the time the program is running.
So, I need a way to do log of the execution of the program.
i dont think is 'cuz of your code... unless you have infinite loops or memory leaks coused by undeleted pointers.... if you have a slower computer, try find a way to make your code shorter
HD accesses are probably not going to be much faster than cout (they might be a little faster, but HD writes are still very slow). So doing a giant text dump to a file will greatly slow down your program any way you slice it.
How slow is "slow"? Several seconds/minutes/forever? How big is your log file getting? Several megabytes? Is your program completing or are you having to force it to shutdown before it exits normally?
Depending on your answer to the above, it might be that your program is spinning in an infinite loop, rather than it being bogged down by cout/file writes.
But anyway this is a shot in the dark. Without more info/code I can't really tell you what the problem is or how to solve it.
edit: blah I'm too slow -- CManowar replied before me ^^. Good catch on the undeleted pointers -- a big memory leak might also be the culprit! Nice.
How slow is "slow"? Several seconds/minutes/forever? How big is your log file getting? Several megabytes? Is your program completing or are you having to force it to shutdown before it exits normally?
Also have you tried removing the file logging? Does that speed it up or is it still slow even without it?
Hey CManowar, using output to file or using cout, the time it takes is more or less the same. About 20mins using output to file and about 20 seconds without output to file. This times are not exacly but I am sure that it runs ten times faster without the cout or fileout.
I realize that the couts were definitely the culprit, but...
You should also consider passing parameters by const reference, as you are definitely taking a performance hit every time you call checkAsymmetricVectors since the vector<vector<vector<double>>> is getting passed by value (ie, completely copied) onto the stack to call the function, and then you are copying it a second time on line 6 of the function.
Likewise, your compare function takes copies of vectors which results in about 20 bytes of stack usage per vectors instance.
In my experience, a very output-heavy program can be dramatically sped up by redirecting output to a file. "Dramatically" being something like 40 times. It obviously depends on the speed of the device the file is being written to and how much output the program produces.
A terminal emulator is one of the slowest I/O devices, though, so you're almost guaranteed to see a performance upgrade.