How can I calculate CLOCKS_PER_SEC.. It is defined as 1000 in ctime. I don't want it defined. I want to calculate the actual value..
I tried the below code but it seems to be giving me my CPU speed.. on a 2.8 Ghz processor, it prints 2800. On a 2.0 Ghz processor it prints 2000.
So what is CLOCKS_PER_SEC and why is it defined as 1000? How can I calculate it? I'm trying to run a function every actual tick.
#include <iostream>
#include <windows.h>
#include <chrono>
#include <thread>
#include <ctime>
std::chrono::time_point<std::chrono::high_resolution_clock> SystemTime()
{
return std::chrono::high_resolution_clock::now();
}
std::uint32_t TimeDuration(std::chrono::time_point<std::chrono::high_resolution_clock> Time)
{
return std::chrono::duration_cast<std::chrono::nanoseconds>(SystemTime() - Time).count();
}
double ClocksPerSecond()
{
std::uint32_t I = 0, Result = 0;
auto Begin = std::chrono::high_resolution_clock::now();
for (I = 0; I < 3; ++I)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
Result += (TimeDuration(Begin) / 1000.0);
}
return Result / I;
}
int main()
{
std::cout<<ClocksPerSecond() / 1000<<std::endl; //ClocksPerSecond() / 1000000;
std::cout<<CLOCKS_PER_SEC;
return 0;
}