precision - Can't get my chrono to count more often than once a ms -
i'm trying code measure time durations shorter 1ms can't.
i've searched around have not managed understand how it. i've added various bits of code found think relevant.
template <class clock> void display_precision() { typedef std::chrono::duration<double, std::nano> ns; ns ns = typename clock::duration(1); std::cout << ns.count() << " ns\n"; } int main() { display_precision<std::chrono::high_resolution_clock>(); display_precision<std::chrono::system_clock>(); display_precision<std::chrono::steady_clock>(); std::cout << std::chrono::high_resolution_clock::period::num << "/" << std::chrono::high_resolution_clock::period::den; std::chrono::high_resolution_clock::time_point nowtime; std::chrono::high_resolution_clock::time_point starttime; starttime = std::chrono::high_resolution_clock::now(); int count = 0; { nowtime = std::chrono::high_resolution_clock::now(); std::chrono::high_resolution_clock::duration diff = nowtime - starttime; __int64 difference = std::chrono::duration_cast<std::chrono::microseconds>(diff).count(); printf("\n%i", difference); count++; if (std::chrono::duration_cast<std::chrono::seconds>(diff).count() > 2) { break; } } while (1); }
the out put looks this:
100 ns 100 ns 100 ns 1 / 10000000
and:
2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2996299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2997299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2998299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 2999299 3000300
as can see, difference
changes once msec , remains constant in between although loops 15 times or in meantime (and though reportedly have 100ns precision).
also, doesn't seem printf bottleneck because tried loading vector data , same results.
[windows 7 professional, vs community 2013]
this problem vs2013, fixed in vs2015. from: visual studio 2015 rtm details
"<chrono> chrono types high_resolution_clock , steady_clock have been fixed. c++11"
Comments
Post a Comment