Added time and memory measurement for windows. (#4)
This commit was merged in pull request #4.
This commit is contained in:
committed by
GitHub
parent
fafe8dbe07
commit
90c8e4f4c0
@@ -5,7 +5,12 @@
|
|||||||
#define __MEMTIME_H__
|
#define __MEMTIME_H__
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#ifdef __WIN32__
|
||||||
|
#include <windows.h>
|
||||||
|
#include <psapi.h>
|
||||||
|
#else
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
#endif
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <malloc/malloc.h>
|
#include <malloc/malloc.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -17,6 +22,25 @@ using namespace std;
|
|||||||
|
|
||||||
typedef long long int64;
|
typedef long long int64;
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
|
||||||
|
static inline double cpuTime()
|
||||||
|
{
|
||||||
|
FILETIME createTime, exitTime, kernelTime, userTime;
|
||||||
|
|
||||||
|
if (!GetProcessTimes(GetCurrentProcess(), &createTime, &exitTime, &kernelTime, &userTime)) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULARGE_INTEGER u;
|
||||||
|
u.LowPart = userTime.dwLowDateTime;
|
||||||
|
u.HighPart = userTime.dwHighDateTime;
|
||||||
|
|
||||||
|
return (double)u.QuadPart / 10e6;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
static inline double cpuTime(void)
|
static inline double cpuTime(void)
|
||||||
{
|
{
|
||||||
struct rusage ru;
|
struct rusage ru;
|
||||||
@@ -24,6 +48,8 @@ static inline double cpuTime(void)
|
|||||||
return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000;
|
return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static inline int memReadStat(void)
|
static inline int memReadStat(void)
|
||||||
{
|
{
|
||||||
char name[256];
|
char name[256];
|
||||||
@@ -47,11 +73,28 @@ static inline int memReadStat(void)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
|
||||||
|
static inline int64 memUsedInt64()
|
||||||
|
{
|
||||||
|
PROCESS_MEMORY_COUNTERS pmc;
|
||||||
|
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
|
||||||
|
return (int64) pmc.WorkingSetSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
static inline int64 memUsedInt64()
|
static inline int64 memUsedInt64()
|
||||||
{
|
{
|
||||||
return (int64)memReadStat() * (int64)getpagesize();
|
return (int64)memReadStat() * (int64)getpagesize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
|
|
||||||
static inline double memUsed()
|
static inline double memUsed()
|
||||||
|
|||||||
Reference in New Issue
Block a user