This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

quick fix for bug in clock() (GNU-Win32 b18)

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() */

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
Tel: (514) 340-4711 poste 5863 Fax: (514) 340-4173
For help on using this list (especially unsubscribing), send a message to
"" with one line of text: "help".

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]