cout is relatively slow. if you are using this in some sort of timer / stopwatch capacity, minimize the number of output statements and it will perform a little better.
Thanks for replying!
I know for sure that cout is slower in some cases, but for avoiding typing-error i'll stick to cout/cin for a while. Thanks for pointing that out though!
Here's something that you can do to speed things up (and make speed-testing more accurate), but is only going to work in an actual terminal or console which many novice users are not comfortable using. I say try to cut out the user from the speed equation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <sstream>
// includes and using namespace, etc.
int main(int argc, char ** argv)
{
if(argc == 2)
{
stringstream ss;
ss << argv[1];
int seconds;
ss >> seconds;
}
else
{
// get seconds via cin and cout, or explain how to use the program from console and exit
// you can get piped input from a script if you accept cin input at this point.
}
// continue with your code from there...
}
The user could then provide the argument from outside the program, instead of holding up its execution time.