Skip to content

Instantly share code, notes, and snippets.

@fresky
Created December 24, 2013 08:28
Show Gist options
  • Save fresky/8110357 to your computer and use it in GitHub Desktop.
Save fresky/8110357 to your computer and use it in GitHub Desktop.
Timer in CPP
#include"windows.h"
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
LARGE_INTEGER Frequency, PerformanceCount1, PerformanceCount2;
void TimeStart(){
QueryPerformanceCounter(&PerformanceCount1);
}
void TimeEnd(){
QueryPerformanceCounter(&PerformanceCount2);
float tdiff = static_cast<float>((
((PerformanceCount2.QuadPart - PerformanceCount1.QuadPart) * 1000) / Frequency.QuadPart));
printf("%f seconds\n", tdiff / 1000);
}
const int loopCount = 10000;
const int vectorCount = 100;
int _tmain(int argc, TCHAR* argv[])
{
QueryPerformanceFrequency(&Frequency);
TimeStart();
for (int loop = 0; loop<loopCount; ++loop)
{
vector<string> vs;
for (size_t i = 0; i<vectorCount; ++i)
vs.push_back("abc" + i);
}
TimeEnd();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment