I was trying out the <ctime> library to get a sense of type, clock_t, the clock() function and the constant, CLOCKS_PER_SEC. I noticed that I would have to namespace both clock_t and clock() with std:: but not CLOCKS_PER_SEC. Why is that? How does CLOCKS_PER_SEC get to float on its own?
#include <ctime>
#include <iostream>
int main() {
std::clock_t start;
double duration;
start = std::clock();
for (long int i = 0; i < 10000000000; i ++){
// do something
}
duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;
std::cout << duration << std::endl;
}
Aucun commentaire:
Enregistrer un commentaire