Created
December 24, 2013 08:28
-
-
Save fresky/8110357 to your computer and use it in GitHub Desktop.
Timer in CPP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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