Задача: Счетчик времени с точностью до микросекунд
Исходник: Timer.cpp (через механизм QueryPerformance), язык: C++ [code #48, hits: 17486]
автор: this [добавлен: 18.02.2006]
  1. #include "Timer.h"
  2.  
  3. Timer::Timer(int n)
  4. {
  5. this->counters = new unsigned __int64[n];
  6. QueryPerformanceFrequency((LARGE_INTEGER*)&freq);
  7. }
  8.  
  9. void Timer::Start(int counter) {
  10. QueryPerformanceCounter((LARGE_INTEGER*)&this->counters[counter]);
  11. }
  12.  
  13. float Timer::Get(int counter, int multiply) {
  14. unsigned __int64 end;
  15. QueryPerformanceCounter((LARGE_INTEGER*)&end);
  16. return (float(end - this->counters[counter]) / freq) * multiply;
  17. }
  18.  
  19. Timer::~Timer(void)
  20. {
  21. delete [] this->counters;
  22. }
  23.  
Timer.cpp :: Реализация класса счетчика времени
Заголовочный файл: Timer.h

Подсчитывает время с точностью до микросекунд.
Тестировалось на: MS Visual Studio 2005, .NET Framework 2.0

+добавить реализацию