Execution time in Custom Test
printf
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, n) for(ll i = a; i < n; ++i)
int main() {
ll n = 10000000;
rep(i, 0, n) printf("%d ", n);
}
- 3587 ms(GNU C++17 9.2.0 (64bit,2msys))
- 1996 ms(GNU C++17 7.3.0)
cout
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, n) for(ll i = a; i < n; ++i)
int main() {
ll n = 10000000;
rep(i, 0, n) cout << 1000000 << " ";
}
- 1138 ms(GNU C++17 9.2.0 (64bit,2msys))
- 1544 ms(GNU C++17 7.3.0)
Does anyone know the reason that printf is twice as slow as cout in C++17(64bit)?