Subject: b19: clock() doesn't work !!!!!!!!!!! and times() too !!!!
From: [email-masked] (Cezary Wagner)

21 Apr 1998 07:13:31 -0700
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="------------C1E816EF5303FA185C0C48EB"
To: [email-masked]

This is a multi-part message in MIME format.
--------------C1E816EF5303FA185C0C48EB
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

(this letter is budle of there that not comes to target (to many hops
!), sorry for not organized style of mail letter ...)

clock() ? 

It always return the same value - it was dirty constnt value ...
It doesn't measure time ...

I test by code like (it should be the best show of problem):

 for(;;)
    cout << clock(); /* or printf */

34838
34838
34838 ... (and so on, forever ...)

and result still is the same (for b19 and b19.1 cygwin.dll) how to
measure
time with it when it constant ???

It was detected it on WIn98 beta 3, and I found that error could be
located it two calls:

GetCurrentProcess
GetProcessTimes

investigate times.cc for better knowledge, for ilustration of that I
attach program + source code (may be my binaries copy is broken ???)

I couldn't remove error because I can't recompile my cygnus b19 source
code (I go throught mounting root problem (hard to find), by I can't
make libg++ now (It stops at libgxx.list target ???)))

Thank you for help
    Cezary (I am wait for your answer whatever It will be)
--------------C1E816EF5303FA185C0C48EB
Content-Type: text/plain; charset=us-ascii; name="prime4.cc"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="prime4.cc"

#include <iostream.h>
#include <ctime>
#include <list>
#include "stopper.hh"

const unsigned max_val = 200000;

int main()
{
        list<unsigned> pl;
        list<unsigned>::iterator i,j,k;
        unsigned u, n, isprime;

        Stopper st;

        st.Start();
        for(u = 2, n = 0, j = k = pl.begin();u != max_val;u++)
                {
                
				for(;j != pl.end()--;j++)
                        /* find last possible divisor for probable prime number */
                        /* current divisor must produce result great then its value
                           to be founded in prime list */
                        /* it based on that holes in prime list is even numbers or
                           numbers dividable by smaller primes than current
                           (see how prime list is builded up (from low to high and the
                            new prime is always greater value than divisors checken on it
                                for prime test commision)) */
                        if(u / *j < *j)
                                break;

                for(i = pl.begin();i != j;i++)
                        {
                        /* check if it not prime */
                        if(u % *i == 0)
                                break;                  /* not prime break */
                        }

                /* check if prime detected */
                if(i == j)
                        {
						n++;
						isprime = 1;
                        pl.insert(pl.end(),u);

						/* fix iterator for first prime from end() position
						   which will be undefinied by inserting first element
						   to the list */
                        if(pl.size() == 1)
                                j = k = pl.begin();
/*                      cout << u << "(" << pl.size() << ")("
                                << *j << ")(" << u / *j << ")\n"; */
                        }
                /* flushing entries every 1000 */
                if(n % 1000 == 0 && n && isprime)
                        {
				        list<unsigned>::iterator last = pl.end();
						st.Stop();
								isprime = 0;
                                cout << *--last << "\n"
									 << clock() << "\n";
						st.Start();
                        }
                }
        st.Stop();
        cout << "time = " << st.Time()
             << " speed = " << (u - 1) / st.Time() << "\n";

        return 0;
}

--------------C1E816EF5303FA185C0C48EB
Content-Type: text/plain; charset=us-ascii; name="Stopper.hh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Stopper.hh"

// --------------------------------------------------------------------------
//
// Name    : stopper.hh.
// Date    : 1996-08-14
// Autor   : Cezary Wagner
// RCS     : $Id: stopper.hh 1.1.1.3 1997/01/04 14:33:44 dosuser Exp $
// Contact : [email-masked]
//           [email-masked] (recommended)
//           [email-masked] (also good)
// Summary : Stopper like you wear on your hand
// Notes   : 
//
// --------------------------------------------------------------------------

#ifndef __STOPPER_HH__
#define __STOPPER_HH__

#include <ctime>

class Stopper
{
	clock_t start_time;
	clock_t stop_time;
	unsigned is_stoped : 1;
public:
	Stopper() { Reset(); }

	inline void Start();
	inline double Time();
	inline void Stop();
	inline void Reset();
};

// --------------------------------------------------------------------------
// Inline definition
// --------------------------------------------------------------------------

void Stopper::Start()
{
	if(is_stoped)
		// if stopper is stopped add time meassured before
		start_time = clock() - (stop_time - start_time);
	is_stoped = 0;
}

double Stopper::Time()
{
	clock_t now_time;

	if(is_stoped)
		// return meassured time
		return (stop_time - start_time) / (double)CLOCKS_PER_SEC;
	// return meanwhile time
	now_time = clock();
	return (now_time - start_time) / (double)CLOCKS_PER_SEC;
}

void Stopper::Stop()
{
	stop_time = clock();
	is_stoped = 1;
}

void Stopper::Reset()
{
	start_time = 0;
	stop_time = 0;
	is_stoped = 1;
}

#endif /* __STOPPER_HH__ */

--------------C1E816EF5303FA185C0C48EB
Content-Type: application/octet-stream; name="a.exe"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="a.exe"

--------------C1E816EF5303FA185C0C48EB
Content-Type: text/plain; charset=us-ascii; name="Tx.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Tx.c"

#include <sys/times.h>
#include <time.h>

int main()
{
	for(;;)
		{
		struct tms tms;
		printf("%d %d (%d %d %d %d)\n", clock(),
			times(&tms) / CLOCKS_PER_SEC,
			tms.tms_cutime, tms.tms_cstime, tms.tms_utime, tms.tms_stime);

		}
	return 0;
}

--------------C1E816EF5303FA185C0C48EB--

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".