///////////////////////////////////////////////////////////////////////////// // ticks.cpp - measuring time on Win32 platforms // // Jim Fawcett, CSE691 - SW Modeling & Analysis, Fall 2000 ///////////////////////////////////////////////////////////////////////////// // Platform: Dell XPS1000, Windows 2000 Professional, SP1 #include #include using namespace std; void main() { cout << "\n Measuring Time on Win32 Platforms " << "\n===================================\n"; cout << "\n unit of time is CLOCKS_PER_SEC = " << CLOCKS_PER_SEC << " ticks per second"; // clock function returns the time since the executing process // started multiplied by the constant CLOCKS_PER_SEC, e.g., // with its current value of that constant, clock() returns // process running time in milliseconds. int count = 0; clock_t t,tprev, tstart; t = tstart = tprev = clock(); while(true) { count++; tprev = t; t = clock(); if(t>tprev) break; } double elapsedTime = double(t-tstart)/double(CLOCKS_PER_SEC); cout << "\n time granularity is: " << elapsedTime << " seconds"; cout << "\n number of iterations: " << count; cout << "\n iteration time = " << elapsedTime/count << " seconds"; cout << "\n\n"; }