Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Calculate/determine the accurate variable timers at the first execution of the program,
- // reguardless if the timer captured any time, print it to the screen.
- // Then keep printing in calculating/determining the accurate variable timers until the program is halted.
- //
- #include <iostream>
- #include <ctime>
- #include <ratio>
- #include <chrono>
- using namespace std::chrono;
- high_resolution_clock::time_point t1 = {};
- high_resolution_clock::time_point t2 = {};
- high_resolution_clock::time_point t3 = {};
- int main ()
- {
- while (1)
- {
- t2 = high_resolution_clock::now();
- // Calculate timer "t3":
- // How to display the correct time elapsed for "t3" for the first execution run? Current implementation will throw false readings:
- // How to determine the time elapsed for "t3" without "t2"?
- std::cout << "\nElapsed time for t3: " << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t3).count() << " Secs\n\n";
- t1 = high_resolution_clock::now();
- int i;
- for (i = 0; i <= 100; i++)
- {
- printf("Hello World\n");
- }
- t2 = high_resolution_clock::now();
- std::cout << "Elapsed time for printf(Hello World): " << std::chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << " Secs\n\n";
- // Timer t3, captures time reference at this point which will be calculated later when main() function loops again.
- t3 = high_resolution_clock::now();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement