Advertisement
Guest User

Untitled

a guest
Oct 7th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1.     uint64_t t1 = 0, t2 = 0, t3 = 0;
  2.     Chrono now;
  3.     for (uint32_t i = 0; i < 100000; ++i)
  4.     {
  5.         char* buf = new char[16];
  6.         strcpy(buf, "blabla");
  7.         delete buf;
  8.     }
  9.     t1 = now.Milliseconds();
  10.  
  11.     now.Reset();
  12.     FILE* f = fopen("temp.txt", "w");
  13.     for (uint32_t i = 0; i < 100000; ++i)
  14.     {
  15.         fprintf(f, "blabla");
  16.     }
  17.     fclose(f);
  18.     t2 = now.Milliseconds();
  19.  
  20.     now.Reset();
  21.     for (uint32_t i = 0; i < 100000; ++i)
  22.     {
  23.         std::cout << "blabla";
  24.     }
  25.     t3 = now.Milliseconds();
  26.  
  27.  
  28.     std::cout << std::endl;
  29.     std::cout << "Memcpy: " << t1 << " ms" << std::endl;    // 5 ms
  30.     std::cout << "file: " << t2 << " ms" << std::endl;  // 30 ms
  31.     std::cout << "cout: " << t3 << " ms" << std::endl;  // 14274 ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement