Skip to content

Commit

Permalink
Add timing facilities.
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfpld committed Mar 5, 2014
1 parent b18ef2e commit 1bc0e1f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Timing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <chrono>

#include "Timing.hpp"

// https://connect.microsoft.com/VisualStudio/feedback/details/719443
#ifdef _WIN32
# include <windows.h>
static double s_freq;
#endif

void InitTiming()
{
#ifdef _WIN32
uint64 freq;
QueryPerformanceFrequency( (LARGE_INTEGER*)&freq );
s_freq = 1.0 / freq;
#endif
}

uint64 GetTime()
{
#ifdef _WIN32
uint64 ret;
QueryPerformanceCounter( (LARGE_INTEGER*)&ret );
return uint64( ret * s_freq * 1000000 );
#else
return std::chrono::time_point_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now() ).time_since_epoch().count();
#endif
}
9 changes: 9 additions & 0 deletions Timing.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __DARKRL__TIMING_HPP__
#define __DARKRL__TIMING_HPP__

#include "Types.hpp"

void InitTiming();
uint64 GetTime();

#endif
2 changes: 2 additions & 0 deletions build/etcpak.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<ClCompile Include="..\ProcessAlpha.cpp" />
<ClCompile Include="..\ProcessRGB.cpp" />
<ClCompile Include="..\Tables.cpp" />
<ClCompile Include="..\Timing.cpp" />
<ClCompile Include="..\zlib\adler32.c" />
<ClCompile Include="..\zlib\compress.c" />
<ClCompile Include="..\zlib\crc32.c" />
Expand Down Expand Up @@ -142,6 +143,7 @@
<ClInclude Include="..\ProcessRGB.hpp" />
<ClInclude Include="..\Semaphore.hpp" />
<ClInclude Include="..\Tables.hpp" />
<ClInclude Include="..\Timing.hpp" />
<ClInclude Include="..\Types.hpp" />
<ClInclude Include="..\Vector.hpp" />
<ClInclude Include="..\zlib\crc32.h" />
Expand Down
2 changes: 2 additions & 0 deletions build/etcpak.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<ClCompile Include="..\zlib\inffas8664.c">
<Filter>zlib</Filter>
</ClCompile>
<ClCompile Include="..\Timing.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\zlib\crc32.h">
Expand Down Expand Up @@ -175,6 +176,7 @@
<ClInclude Include="..\ProcessAlpha.hpp" />
<ClInclude Include="..\ProcessRGB.hpp" />
<ClInclude Include="..\ProcessCommon.hpp" />
<ClInclude Include="..\Timing.hpp" />
</ItemGroup>
<ItemGroup>
<Object Include="..\zlib\inffasx64.obj">
Expand Down

0 comments on commit 1bc0e1f

Please sign in to comment.