Water's Home

Just another Life Style

0%

Speed up by ignoring std::cout

Test Code

#include int main(int argc, char *argv[])
{
//std::cout.setstate(std::ios_base::badbit);
for(int i = 0; i < 100; i ++) {
for(int i = 0; i < 100; i ++) {
;//std::cout << “” << std::endl;
}
}
return 0;
}

Test it without std::cout

root@imx6ul7d:~/tmp# time ./t1_1

real 0m0.041s
user 0m0.020s
sys 0m0.000s

Test it with std::cout, but redirect to /dev/null

root@imx6ul7d:~/tmp# time ./t1_0 > /dev/null

real 0m0.096s
user 0m0.030s
sys 0m0.030s

Test it with std::cout, but set io state

root@imx6ul7d:~/tmp# time ./t1_2

real 0m0.061s
user 0m0.040s
sys 0m0.000s