For some reason, I can't get the output stream to work faster with the line
std::ios_base::sync_with_stdio(false);
included at the beginning of my program. I am testing this with these two programs:
#include <iostream>
int main() {
for (int i = 0; i < 500000; i++)
std::cout << "Hello World\n";
}
and
#include <iostream>
int main() {
std::ios_base::sync_with_stdio(false);
for (int i = 0; i < 500000; i++)
std::cout << "Hello World\n";
}
The runtime for each program is as follows
first_test (synchronized)
real 0m1.095s
user 0m0.472s
sys 0m0.299s
second_test (with sync disabled)
real 0m1.091s
user 0m0.471s
sys 0m0.299s
I am compiling with g ++ -O3 main.cpp. I'm working on Mac 10.11.1.
Is there a way to speed up the execution of the output stream by disabling sync_with_stdio?
source
share