t1nman

time measurment example

Mar 26th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime> // or <time.h> for old compilers
  3.  
  4. void func();
  5.  
  6. int main()
  7. {
  8.     using namespace std;
  9.  
  10.     clock_t start, finish;
  11.     double total(0);
  12.  
  13.     start = clock();
  14.     func();
  15.     finish = clock();
  16.     total = (double)(finish - start)/CLOCKS_PER_SEC;
  17.     cout << total << " seconds\n";
  18.  
  19.     return 0;
  20. }
  21.  
  22. void func()
  23. {
  24.     for (long i = 0; i < 1000000000; i++)
  25.         ;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment