Subject: quick fix for bug in clock() (GNU-Win32 b18)
From: [email-masked] (Richard Gourdeau)

29 Nov 1997 03:08:21 -0800
Message-ID: <[email-masked]>
Reply-To: [email-masked]
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
To: [email-masked]

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