Você está na página 1de 3

// CodeTimer.cpp : main project file.

// Using Query Performance Counter.

#include <stdafx.h>
#include <tchar.h>
#include <windows.h>
#include <iostream.h>
#include <fstream.h>

using namespace System;


using namespace std;

int main()
{
// Prepare log for output.
ofstream timeLog ("log.txt");

if (timeLog.is_open())
{
cout << "Events Detected\n";
cout << "---------------\n\n";
//timeLog.close();
}

else cout << "Unable to open file";

// Initialize timer when condition met.


int never = 0;
int clap = 0;
while(never == 0)
{
// Audio signal event detection.

// Timer series.
__int64 ctr1 = 0, ctr2 = 0, freq = 0;
int acc = 0, i = 0;

// Start timing the code.


if (QueryPerformanceCounter((LARGE_INTEGER *)&ctr1)!= 0)
{
// Code segment is being timed.
while (clap != 1)
{
acc++;

if (clap == 1)
{
timeLog << "Event logged\n";
}
}

// Finish timing the code.


QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);

Console::WriteLine("Start Value: {0}",ctr1.ToString());


Console::WriteLine("End Value: {0}",ctr2.ToString());

QueryPerformanceFrequency((LARGE_INTEGER *)&freq);
Console::WriteLine(S"QueryPerformanceCounter minimum resolution: 1/{
0} Seconds.",freq.ToString());
// In Visual Studio 2005, this line should be changed to: Console::W
riteLine("QueryPerformanceCounter minimum resolution: 1/{0} Seconds.",freq.ToStr
ing());
Console::WriteLine("100 Increment time: {0} seconds.",((ctr2 - ctr1)
* 1.0 / freq).ToString());
}
else
{
DWORD dwError = GetLastError();
Console::WriteLine(S"Error value = {0}",dwError.ToString());// In Vi
sual Studio 2005, this line should be changed to: Console::WriteLine("Error valu
e = {0}",dwError.ToString());
}

// Make the console window wait.


Console::WriteLine();
Console::Write("Press ENTER to finish.");
Console::Read();
}

return 0;
}

Você também pode gostar