diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-10-29 15:47:56 -0400 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2009-10-29 15:47:56 -0400 |
commit | a2268ca6b3b3dc132c984c6e7eacf13af3ef3428 (patch) | |
tree | 891fdf0fa2b42c1079a2f55cce9788a9c78d898b /bench/BenchTimer.h | |
parent | d0562bd47392f94abe98b1bc377a4647af21257c (diff) |
properly implement BenchTimer on POSIX
(may require a platform check for the clock name on non-linux platforms)
Diffstat (limited to 'bench/BenchTimer.h')
-rw-r--r-- | bench/BenchTimer.h | 16 |
1 files 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 <g.gael@free.fr> -// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> +// Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com> // // 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 <sys/time.h> +#include <time.h> #include <unistd.h> #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 } |