public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Why does std::chrono now() uses slow syscall?
@ 2014-01-26  7:50 Keith Erickson
  2014-01-26 10:33 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Erickson @ 2014-01-26  7:50 UTC (permalink / raw)
  To: gcc-help

When I do this:

#include <chrono>
#include <iostream>

using Clk = std::chrono::high_resolution_clock;
int main() {
    auto t1 = Clk::now();
    auto t2 = Clk::now();
    std::cout << "Chrono: " << (t2-t1).count() << "ns" << std::endl;
}

I get results of about 1.5us to do the clock operations.  When I do
the same thing in C using clock_gettime, it's on the order of 250ns.
When I run the above code on ideone.com, I get the expected C time of
about 250ns.  I traced this down to the fact that my version of
chrono.cc got compiled with _GLIBCXX_USE_CLOCK_GETTIME_SYSCALL
defined, and so I was using the absurdly slow syscall to get time
instead of the very fast clock_gettime().

My questions, then, are....  why would I ever want to use the syscall
version?  It seems that configure prefers it, and will use it if it's
available.  But it's stupidly slow, even on the fasted server CPU that
AMD sells (Opteron 6386 SE at the time of this writing).  How do I not
use this slow method?  Do I have to compile gcc specially?  What are
the drawbacks to forcing configure to not set that #define?  Is there
an approved way to tell configure to use a fast time?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-27  0:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-26  7:50 Why does std::chrono now() uses slow syscall? Keith Erickson
2014-01-26 10:33 ` Jonathan Wakely
     [not found]   ` <CA+PNwROZe3T4FBn1Kv7MES=b9=X95X81VXEapeiMOi7R65Jh1Q@mail.gmail.com>
2014-01-27  0:12     ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).