Josh Posted August 25 Share Posted August 25 This is what I use for some internal timing stuff: #ifdef _WIN32 double PCFreq = 0.0; __int64 CounterStart = 0; bool counterstarted = false; #endif double fMillisecs() { #ifdef _WIN32 //return GetTickCount64(); // this only updates every 16 milliseconds, don't use it! //return timeGetTime(); if (!counterstarted) { LARGE_INTEGER li; QueryPerformanceFrequency(&li); PCFreq = double(li.QuadPart) / 1000.0; QueryPerformanceCounter(&li); CounterStart = li.QuadPart; counterstarted = true; } LARGE_INTEGER li; QueryPerformanceCounter(&li); //return (((double(li.QuadPart - CounterStart) / PCFreq) * 1000.0)) / 1000.0; return double(li.QuadPart - CounterStart) / PCFreq; #else long t; struct timeval tv; gettimeofday(&tv, 0); long secstomillisecs = 1000; t = tv.tv_sec * secstomillisecs; t += tv.tv_usec / 1000.0; return t; #endif } 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Dreikblack Posted August 25 Share Posted August 25 Thats what Canardia uses, but i was not sure if it's fine to use for not profiling purposes but i see it is now. His code: // Stopwatch.h #pragma once class Stopwatch { public: LARGE_INTEGER StartTime, Frequency, StopTime, ElapsedTime; Stopwatch(); void Start(); double Elapsed(); }; // Stopwatch.cpp #include "UltraEngine.h" #include "Stopwatch.h" Stopwatch::Stopwatch() { QueryPerformanceFrequency(&Frequency); } void Stopwatch::Start() { QueryPerformanceCounter(&StartTime); } double Stopwatch::Elapsed() { QueryPerformanceCounter(&StopTime); ElapsedTime.QuadPart = StopTime.QuadPart - StartTime.QuadPart; return (double)(ElapsedTime.QuadPart) / (Frequency.QuadPart); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.