Why is printf too slow in C++17(64bit)?

Правка en2, от Hyado, 2020-08-11 15:04:59

Execution time in Custom Test

#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) \n
#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)
#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() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n = 10000000;
  rep(i, 0, n) cout << 1000000 << " ";
}
  • 1388 ms(GNU C++17 9.2.0 (64bit,2msys))
  • 1544 ms(GNU C++17 7.3.0)

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский Hyado 2020-08-11 15:21:13 165 (published)
en4 Английский Hyado 2020-08-11 15:18:55 108 Tiny change: 'ecause of too slow printf.\n\nI meas' -> 'ecause of printf (´・_・`)\n\nI meas'
en3 Английский Hyado 2020-08-11 15:13:50 378 Tiny change: 'tom Test\n\n\n~~~~' -> 'tom Test\n=============================\n\n\n~~~~'
en2 Английский Hyado 2020-08-11 15:04:59 103 Tiny change: 'it,2msys)) \n\n1996 m' -> 'it,2msys))\n\n1996 m'
en1 Английский Hyado 2020-08-11 14:59:11 887 Initial revision (saved to drafts)