Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #define TO_MilSec(_X_) (_X_*1000)
- #define TO_Sec(_X_) _X_
- #define TO_MicroSec(_X_) (_X_*1000000)
- #define TO_KB_CEIL(_X_) ceil(double(_X_) / 1024.0)
- #define TO_MB_CEIL(_X_) ceil(TO_KB_CEIL(_X_) / 1024.0)
- class CPUBenchmark
- {
- LARGE_INTEGER _startCounter, _elapsedTicks, _frequency;
- LONGLONG _lastResultInMilliSec;
- public:
- CPUBenchmark()
- {
- QueryPerformanceCounter(&_startCounter);
- }
- _inline void restart()
- {
- QueryPerformanceCounter(&_startCounter);
- }
- _inline long long stop()
- {
- LARGE_INTEGER endCounter;
- QueryPerformanceCounter(&endCounter);
- _elapsedTicks.QuadPart = endCounter.QuadPart - _startCounter.QuadPart;
- QueryPerformanceFrequency(&_frequency);
- _lastResultInMilliSec = TO_MilSec(_elapsedTicks.QuadPart) / _frequency.QuadPart;
- return _elapsedTicks.QuadPart;
- }
- _inline long long getLastResultMilli() const
- {
- return _lastResultInMilliSec;
- }
- _inline long long getLastResult() const
- {
- return _elapsedTicks.QuadPart;
- }
- _inline void printBench()
- {
- printf_s(">>>> Elapsed Tick: %llld\n"
- ">>>> Elapsed Time: %llldms\n",
- _elapsedTicks.QuadPart, _lastResultInMilliSec);
- }
- };
- ////////////////////////////////////////////////
- #include <Psapi.h>
- class MemoryBenchmark
- {
- ////Memory Benchmark
- MEMORYSTATUSEX _memInfo;
- PROCESS_MEMORY_COUNTERS_EX _pmc;
- DWORDLONG _totalVMem, _totalVMemUsed, _totalPhysMem, _totalPhysMemUsed;
- DWORDLONG _totalVMemUsedByMe, _totalPhysMemUsedByMe;
- public:
- MemoryBenchmark(){ recalculateMem(); }
- _inline void recalculateMem()
- {
- getTotalMem(); getCurrentMemByme();
- }
- _inline void getTotalMem()
- {
- _memInfo.dwLength = sizeof(MEMORYSTATUSEX);
- GlobalMemoryStatusEx(&_memInfo);
- _totalVMem = TO_KB_CEIL(_memInfo.ullTotalPageFile);
- _totalVMemUsed = TO_KB_CEIL(_memInfo.ullTotalPageFile - _memInfo.ullAvailPageFile);
- _totalPhysMem = TO_KB_CEIL(_memInfo.ullTotalPhys);
- _totalPhysMemUsed = TO_KB_CEIL(_memInfo.ullTotalPhys - _memInfo.ullAvailPhys);
- }
- _inline long long getCurrentMemByme()
- {
- GetProcessMemoryInfo(GetCurrentProcess(), (PROCESS_MEMORY_COUNTERS*)&_pmc, sizeof(_pmc));
- _totalVMemUsedByMe = TO_KB_CEIL(_pmc.PrivateUsage);
- _totalPhysMemUsedByMe = TO_KB_CEIL(_pmc.WorkingSetSize);
- return _totalVMemUsedByMe + _totalPhysMemUsedByMe;
- }
- _inline void printTotalMemory()
- {
- printf_s(">>>> Total Virutal Mem: %llldKB\n"
- ">>>> Total Physcal Mem: %llldKB\n"
- ">>>> Total Used VM Mem: %llldKB\n"
- ">>>> Total Used Ph Mem: %llldKB\n"
- , _totalVMem, _totalPhysMem, _totalVMemUsed, _totalPhysMemUsed);
- }
- _inline void printMemoryByMe()
- {
- printf_s(">>>> Used VirMem by Me: %llldKB\n"
- ">>>> Used Phymem by Me: %llldKB\n"
- ,_totalVMemUsedByMe, _totalPhysMemUsedByMe);
- }
- _inline long long getVMUsedByMe() const
- {
- return _totalVMemUsedByMe;
- }
- _inline long long getPhysUsedByMe() const
- {
- return _totalPhysMemUsedByMe;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement