Главная
>>
Каталог задач
>>
Время
>>
Счетчики
>>
Счетчик времени с точностью до микросекунд
Счетчик времени с точностью до микросекунд
реализации: C++, количество: 2
Aвтор: this
Дата: 26.01.2004
Просмотров: 114666
Рейтинг:
3/7,4.81(3792)
+
реализации(исходники)
+добавить
С точностью до микросекунд считаем время выполнения.
Реализации:
C++(2),
C#(2)
+добавить реализацию
1)
Timer.h (через механизм QueryPerformance), code #47[автор:this]
#pragma once
#include <windows.h>
class Timer
{
private:
unsigned __int64* counters;
unsigned __int64 freq;
public:
Timer(int = 1);
void Start(int = 0);
float Get(int = 0, int = 1);
public:
~Timer(void);
};
2)
Timer.cpp (через механизм QueryPerformance), code #48[автор:this]
#include "Timer.h"
Timer::Timer(int n)
{
this->counters = new unsigned __int64[n];
QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
}
void Timer::Start(int counter) {
QueryPerformanceCounter((LARGE_INTEGER*)&this->counters[counter]);
}
float Timer::Get(int counter, int multiply) {
unsigned __int64 end;
QueryPerformanceCounter((LARGE_INTEGER*)&end);
return (float(end - this->counters[counter]) / freq) * multiply;
}
Timer::~Timer(void)
{
delete [] this->counters;
}