Keith Erickson
2014-01-26 07:50:16 UTC
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?
#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?