Dear forum members!
I have seen some discussion on how to measure the running time of a C ++ program on my forum, but the input data must be large enough.
Can you help me to measure the running time of a C ++ program with small input data.
For example, a simple command is to print the string "cplusplus" to the screen, I want to measure its running time (although it is very very small).
This is a timepiece program for your screen, write by CodeBlock:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <iomanip>
#include <ctime>
int main ()
{
float t = clock();
std::cout<<"cplusplus"<<" printed in the screen during the time "
<<std::setprecision(20)<<(clock()-t)/1000<< "s";
}
The result I get is always 0s, despite the exact 20-digit formatting in the output.
I look forward to receiving the explanation, suggestions to solve this problem. Thank you sincerely for your help!