I need to measure execution time of the program using clock() function. The whole algorithm consists of the input of one character.
I found how to measure time with clock() here: How to use clock() in C++.
#include <cstdio>
#include <ctime>
int main() {
std::clock_t start;
double duration;
start = std::clock();
std::cout << "Press a key followed by ENTER: ";
char c;
cin >> c;
duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
std::cout<<"printf: "<< duration <<'\n';
}
Program always output 0. This is due to the fact that when performing cin, there are no processor counts? How can I handle this problem?