//----------------------------------------------------------------------
//
// Zeitmessung im µs-Bereich
// TESTANWENDUNG
// Author: tbird
// Date: 20.11.2007
//
//----------------------------------------------------------------------
//#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include <string>
#include <iostream>
#include "math.h"
using namespace std;
int main(int argc, char* argv[])
{
//Variablen
LONGLONG g_Frequency, g_FirstNullCount, g_LastNullCount, g_FirstCount, g_LastCount;
//Frequenz holen
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&g_Frequency))
printf("Performance Counter nicht vorhanden");
double resolution = 1000000 / ((double)g_Frequency);
printf("Frequenz des Counters: %lld kHz\n", g_Frequency/1000); //lld -> LONGLONG darstellung
printf("Dadurch maximale Aufloesung: %4.5f us\n", resolution);
//null-messung
QueryPerformanceCounter((LARGE_INTEGER*)&g_FirstNullCount);
QueryPerformanceCounter((LARGE_INTEGER*)&g_LastNullCount);
double nulltime = (((double)(g_LastNullCount-g_FirstNullCount))/((double)g_Frequency));
printf("Null-Zeit: %4.5f us\n", nulltime * 1000000);
//beginn messung
QueryPerformanceCounter((LARGE_INTEGER*)&g_FirstCount);
//hier das rein was zeit braucht
long j=0;
for(long i=0; i<10000; i++)
{
j++;
}
//2. Messung
QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
double dTimeDiff = (((double)(g_LastCount-g_FirstCount))/((double)g_Frequency));
//Von der gemessenen Zeit die "Null-Zeit" abziehen, um genauer zu werden
double time = (dTimeDiff - nulltime) * 1000000; //mikro-sekunden
printf("Zeit: %4.5f us\n" ,time);
//warten auf tastendruck
string dummy;
getline(cin, dummy);
return 0;
}