fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using namespace chrono;
  4.  
  5. constexpr int SIZE = 100000;
  6. constexpr int TIMES = 10000;
  7.  
  8. struct Type {
  9. int r, g, b;
  10. };
  11.  
  12. int main() {
  13. vector<Type> v1( SIZE );
  14. vector<Type> v2( v1 );
  15.  
  16. for( int i = TIMES; i--; ) {
  17. copy( v1.begin(), v1.end(), v2.begin() );
  18. }
  19.  
  20. auto t2 = steady_clock::now();
  21. for( int i = TIMES; i--; ) {
  22. copy( v1.begin(), v1.end(), v2.begin() );
  23. }
  24. cout << "std::copy: ";
  25. cout << duration_cast<milliseconds>( steady_clock::now() - t2 ).count() << endl;
  26.  
  27. auto t1 = steady_clock::now();
  28. for( int i = TIMES; i--; ) {
  29. memcpy( v2.data(), v1.data(), v1.size() * sizeof( Type ) );
  30. }
  31. cout << "memcpy: ";
  32. cout << duration_cast<milliseconds>( steady_clock::now() - t1 ).count() << endl;
  33. }
Success #stdin #stdout 1.73s 5040KB
stdin
Standard input is empty
stdout
std::copy: 550
memcpy: 548