From a2268ca6b3b3dc132c984c6e7eacf13af3ef3428 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Thu, 29 Oct 2009 15:47:56 -0400 Subject: properly implement BenchTimer on POSIX (may require a platform check for the clock name on non-linux platforms) --- bench/BenchTimer.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bench/BenchTimer.h b/bench/BenchTimer.h index c1f473597..70173427f 100644 --- a/bench/BenchTimer.h +++ b/bench/BenchTimer.h @@ -2,7 +2,7 @@ // for linear algebra. // // Copyright (C) 2008 Gael Guennebaud -// Copyright (C) 2006-2008 Benoit Jacob +// Copyright (C) 2009 Benoit Jacob // // Eigen is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -27,7 +27,7 @@ #define EIGEN_BENCH_TIMER_H #ifndef WIN32 -#include +#include #include #else #define NOMINMAX @@ -41,6 +41,11 @@ namespace Eigen { /** Elapsed time timer keeping the best try. + * + * On POSIX platforms we use clock_gettime with CLOCK_PROCESS_CPUTIME_ID. + * On Windows we use QueryPerformanceCounter + * + * Important: on linux, you must link with -lrt */ class BenchTimer { @@ -83,10 +88,9 @@ public: QueryPerformanceCounter(&query_ticks); return query_ticks.QuadPart/m_frequency; #else - struct timeval tv; - struct timezone tz; - gettimeofday(&tv, &tz); - return (double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec; + timespec ts; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts); + return double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec); #endif } -- cgit v1.2.3