This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
quick fix for bug in clock() (GNU-Win32 b18)
- To: gnu-win32 at cygnus dot com
- Subject: quick fix for bug in clock() (GNU-Win32 b18)
- From: Richard Gourdeau <rgourdeau at mail dot polymtl dot ca>
- Date: Fri, 28 Nov 1997 20:40:40 -0500
- Organization: École Polytechnique
- Reply-To: rgourdeau at mail dot polymtl dot ca
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@mail.polymtl.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@cygnus.com" with one line of text: "help".