opj_decompress: use clock_gettime() instead of getrusage() so as to get the time spent, and not to the total CPU time
This commit is contained in:
parent
d67cd2220a
commit
69497d35c0
|
@ -57,6 +57,9 @@ foreach(exe opj_decompress opj_compress opj_dump)
|
||||||
# On unix you need to link to the math library:
|
# On unix you need to link to the math library:
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
target_link_libraries(${exe} m)
|
target_link_libraries(${exe} m)
|
||||||
|
IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
||||||
|
target_link_libraries(${exe} rt)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
# Install exe
|
# Install exe
|
||||||
install(TARGETS ${exe}
|
install(TARGETS ${exe}
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "windirent.h"
|
#include "windirent.h"
|
||||||
|
@ -907,17 +908,22 @@ OPJ_FLOAT64 opj_clock(void) {
|
||||||
/* t is the high resolution performance counter (see MSDN) */
|
/* t is the high resolution performance counter (see MSDN) */
|
||||||
QueryPerformanceCounter ( & t ) ;
|
QueryPerformanceCounter ( & t ) ;
|
||||||
return freq.QuadPart ? (t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) : 0;
|
return freq.QuadPart ? (t.QuadPart / (OPJ_FLOAT64)freq.QuadPart) : 0;
|
||||||
|
#elif defined(__linux)
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
return( ts.tv_sec + ts.tv_nsec * 1e-9 );
|
||||||
#else
|
#else
|
||||||
/* Unix or Linux: use resource usage */
|
/* Unix : use resource usage */
|
||||||
struct rusage t;
|
/* FIXME: this counts the total CPU time, instead of the user perceived time */
|
||||||
OPJ_FLOAT64 procTime;
|
struct rusage t;
|
||||||
/* (1) Get the rusage data structure at this moment (man getrusage) */
|
OPJ_FLOAT64 procTime;
|
||||||
getrusage(0,&t);
|
/* (1) Get the rusage data structure at this moment (man getrusage) */
|
||||||
/* (2) What is the elapsed time ? - CPU time = User time + System time */
|
getrusage(0,&t);
|
||||||
|
/* (2) What is the elapsed time ? - CPU time = User time + System time */
|
||||||
/* (2a) Get the seconds */
|
/* (2a) Get the seconds */
|
||||||
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
|
procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec);
|
||||||
/* (2b) More precisely! Get the microseconds part ! */
|
/* (2b) More precisely! Get the microseconds part ! */
|
||||||
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
|
return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue