User talk:Mgkrupa

high_resolution_clock
hi, your cpp/chrono/high_resolution_clock is larger than the rest of the page it's on, and it's not clear that it shows good practice: while we've all done something like that (in fact, cpp/chrono/c/clock and cpp/thread/sleep_for do exactly that), there are no barriers to prevent the code motion around the calls to now or dead store elimination (in fact, the ideal compiler should return zero for both of your timings!), and it's not trying to make the measurements statistically significant. If you really want to show timing, how about simplifying to a simple difference like in cpp/thread/sleep_for? --Cubbi (talk) 11:06, 17 July 2017 (PDT)
 * My understanding is that compilers can't rearrange calls to functions whose definitions are not available at compile time. Presumably, somewhere inside of now's definition there is a call to such a function or is now independent of the OS? As for the variance, you're correct. I had previously divided by only one of the two variables in the denominator but now that that's no longer the case, only one loop is necessary. "the ideal compiler should return zero for both of your timings!" - then I'm fortunate that I don't live in an ideal world (unfortunately). Mgkrupa (talk) 17:01, 17 July 2017 (PDT)
 * somewhere in now there is an opaque system call, true, but both vector assignment and the sorts can be inlined, allocate/deallocate can annihilate each other (clang loves doing that), and then it will see that now can't possible access any of the vector elements.. to be fair, I checked and neither gcc nor clang were that smart on your example. --Cubbi (talk) 19:29, 17 July 2017 (PDT)
 * Thank you for that great insight. I think that the code below should solve all of the problems that you mentioned.Mgkrupa (talk) 01:04, 19 July 2017 (PDT)


 * the main problem is that this is an attempt to demonstrate microbechmarking and not an example of std: the majority of code does not do anything with it and the part that does (the three calls to now) does not add anything to what's already in cpp/chrono/high_resolution_clock/now. If you're interested in microbenchmark design, take a look at google/benchmark for ideas, in particular ClobberMemory and DoNotOptimize. --Cubbi (talk) 07:29, 19 July 2017 (PDT)
 * Thanks a lot. BTW, the code above wasn't meant to be placed on cpp/chrono/high_resolution_clock.Mgkrupa (talk) 07:33, 20 July 2017 (PDT)