here is an example of teh difference between before c++11 and now
this is hwo dreadful the old timer function was, and tshi has diffrent implementation for different platforms all with different granularity and scaling
- Code: Select all
dUnsigned64 dGetTimeInMicrosenconds()
{
static LARGE_INTEGER frequency;
static LARGE_INTEGER baseCount;
if (!frequency.QuadPart) {
QueryPerformanceFrequency(&frequency);
QueryPerformanceCounter(&baseCount);
}
LARGE_INTEGER count;
QueryPerformanceCounter(&count);
count.QuadPart -= baseCount.QuadPart;
dUnsigned64 timeStamp = dUnsigned64(count.QuadPart * LONGLONG(1000000) / frequency.QuadPart);
return timeStamp;
}
here is the new function
- Code: Select all
dUnsigned64 dGetTimeInMicrosenconds()
{
static std::chrono::high_resolution_clock::time_point timeStampBase = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point currentTimeStamp = std::chrono::high_resolution_clock::now();
dUnsigned64 timeStamp = std::chrono::duration_cast<std::chrono::microseconds>(currentTimeStamp - timeStampBase).count();
return timeStamp;
}
and this apply to stuff like threads, atomics, and even the stl containers, although I am not using STL containers as I beleive mine are far better by order of magnitude in performance and eassy to use.
I actually test this many time before, and to get an stl container to be come with the newton ones, you need to add special memory allocators. but even with that the eassy to use factor is important.
same apply to stuff like Mutex and atomics.
window Critical section are about 10 to 20 time faster that the general std::mutex
so are atomics.
windows atomics reduce to one cpu instruction, while SLT atomics are hundred of instructions, no sure why is this, but in these cases the eassy to use and cross platform funtionality is a winner,
since usage of those synchronization objects is small, mostly in the most outer loops, over the engine.