How do you time execution time?. I am writing a program in C++ to calculate Pi with a desired degree of precision/digits after the decimal point, and I have to calculate the time it takes to calculate for each desired precision. Can anyone help me? :o
Decoder
0
Newbie Poster
Recommended Answers
Jump to PostIf you want any decent timings, you'll use a profiler. But you can use a poor man's timer with the standard library. For example:
…#include <ctime> std::clock_t start = std::clock(); /* Stuff to time here */ std::cout<< ( ( std::clock() - start ) / (double)CLOCKS_PER_SEC ) <<'\n';
Jump to Postclock_t is not a part of namespace std
All 7 Replies
Narue
5,707
Bad Cop
Team Colleague
Decoder
0
Newbie Poster
SpS
34
Posting Pro
Stoned_coder
6
Junior Poster
SpS
34
Posting Pro
Narue
5,707
Bad Cop
Team Colleague
Drowzee
3
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.