/CycleClock

High accuracy CPU-cycle-based clock for Windows/Intel. Suitable for music sequencing.

Primary LanguageC++

CycleClock

High accuracy CPU-cycle-based clock. Suitable for music sequencing.
Only runs on Windows with Intel CPU.

Usage:

#################################

#include "CycleClock.h"

class MyApp
{
public:
   MyApp();
private:
   CycleClockRef mClock;
   double mCpuFreq;
   void onTick();
};

using namespace std;

MyApp::MyApp()
{
  mCpuSpeed = 0.0;
  mClock = CycleClock::create();
  mClock->connectEventHandler( &MyApp::onTick, this );
  mClock->tick( 0.000001, true ); // Second argument repeats
}

MyApp::onTick()
{
  if ( mCpuSpeed == 0.0 ) {
    mCpuFreq = mClock->getCpuFreq();
	cout << "CPU speed: " << mCpuFreq << endl;
  }
  cout << "tick" << endl;
}

int main( int argc, char* argv[] )
{
  MyApp app;
  for ( size_t i = 0; i < 10000; ++i ) {
    // Let it run for a bit
  }
  return 0;
}