mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-09-19 04:43:13 +08:00
properly implement BenchTimer on POSIX
(may require a platform check for the clock name on non-linux platforms)
This commit is contained in:
parent
d0562bd473
commit
a2268ca6b3
@ -2,7 +2,7 @@
|
|||||||
// for linear algebra.
|
// for linear algebra.
|
||||||
//
|
//
|
||||||
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
// 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
|
// Eigen is free software; you can redistribute it and/or
|
||||||
// modify it under the terms of the GNU Lesser General Public
|
// modify it under the terms of the GNU Lesser General Public
|
||||||
@ -27,7 +27,7 @@
|
|||||||
#define EIGEN_BENCH_TIMER_H
|
#define EIGEN_BENCH_TIMER_H
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
#include <sys/time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
@ -41,6 +41,11 @@ namespace Eigen
|
|||||||
{
|
{
|
||||||
|
|
||||||
/** Elapsed time timer keeping the best try.
|
/** 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
|
class BenchTimer
|
||||||
{
|
{
|
||||||
@ -83,10 +88,9 @@ public:
|
|||||||
QueryPerformanceCounter(&query_ticks);
|
QueryPerformanceCounter(&query_ticks);
|
||||||
return query_ticks.QuadPart/m_frequency;
|
return query_ticks.QuadPart/m_frequency;
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
timespec ts;
|
||||||
struct timezone tz;
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
|
||||||
gettimeofday(&tv, &tz);
|
return double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
|
||||||
return (double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user