Mail Archives: cygwin/1997/11/29/03:08:21
I have been using GNU-Win32 to do numerical computations.
When attempting to benchmark some programs, I have realized
than the function clock() does not work as expected.
The following C++ program presents a quick fix to this problem.
It has the advantage of not requiring to rebuild any of the
files in the distribution.
/* clock() example begin */
#include <time.h>
#include <iostream.h>
#include <windows.h>
#if defined(_WIN32) /* Windows 95/NT */
#ifdef __GNUG__ /* Cygnus Gnu C++ for win32*/
#define clock() GetTickCount() /* quick fix for bug in clock() */
#endif
#endif
int main(void)
{
clock_t start, end;
start = clock();
cout << "Clock start: " << start << "\n";
Sleep(2000); /* waits 2 sec */
end = clock();
cout << "Clock end: " << end << "\n";
cout << "The time was: "<< ((end - start) / (double)CLK_TCK) << "\n";
return 0;
}
/* clock() example end */
===================================================
Richard Gourdeau, Professeur Agrégé
Departement de mathematiques et de genie industriel
Ecole Polytechnique de Montreal
C.P. 6079, Succ. Centre-ville
Montreal (Quebec), Canada
email: rgourdeau AT mail DOT polymtl DOT ca
Tel: (514) 340-4711 poste 5863 Fax: (514) 340-4173
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -