X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f X-Received: by 10.224.172.129 with SMTP id l1mr5805885qaz.4.1373252369494; Sun, 07 Jul 2013 19:59:29 -0700 (PDT) X-Received: by 10.50.66.134 with SMTP id f6mr986595igt.13.1373252369459; Sun, 07 Jul 2013 19:59:29 -0700 (PDT) Newsgroups: comp.os.msdos.djgpp Date: Sun, 7 Jul 2013 19:59:29 -0700 (PDT) In-Reply-To: <201307072036.r67KanNk031567@delorie.com> Complaints-To: groups-abuse AT google DOT com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.34.83.153; posting-account=jrLHRgkAAABPV01ZW_RN_U6Tm5UnYNUx NNTP-Posting-Host: 71.34.83.153 References: <201307072036 DOT r67KanNk031567 AT delorie DOT com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <930fe945-22b9-4000-80fc-e42858b8f498@googlegroups.com> Subject: Re: CLOCKS_PER_SEC of time.h doesn't work to prove it is a value for one second From: "K.J.Williams" Injection-Date: Mon, 08 Jul 2013 02:59:29 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 3995 Bytes: 4212 Lines: 105 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id r683F1RD008785 Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sunday, July 7, 2013 1:36:49 PM UTC-7, DJ Delorie wrote: > > ticks1=clock(); > > > ticks2=ticks1; > > > while((ticks2/CLOCKS_PER_SEC-ticks1/CLOCKS_PER_SEC)<1) > > > ticks2=clock(); > > > > What you should do is write a djgpp program that prints clock()'s > > value to the screen, and time it from 0 to 9100 clock()s with a > > stopwatch. > I am not familiar with how clock() is implemented for DJGPP but according to : http://en.cppreference.com/w/c/chrono/clock they state: Defined in header clock_t clock(); Returns the approximate processor time used by the process since the beginning of an implementation-defined era related to the program's execution. To convert result value to seconds divide it by CLOCKS_PER_SEC. Only the difference between two values returned by different calls to clock is meaningful, as the beginning of the clock era does not have to coincide with the start of the program. clock time may advance faster or slower than the wall clock, depending on the execution resources given to the program by the operating system. For example, if the CPU is shared by other processes, clock time may advance slower than wall clock. On the other hand, if the current process is multithreaded and more than one execution core is available, clock time may advance faster than wall clock. Parameters: (none) Return value: Processor time used by the program so far or (clock_t)(-1) if that information is unavailable. Notes: On POSIX-compatible systems, clock_gettime with clock id CLOCK_PROCESS_CPUTIME_ID offers better resolution. The value returned by clock() may wrap around on some implementations. For example, on a machine with 32-bit clock_t, it wraps after 2147 seconds or 36 minutes. Thanks > > > All your code is doing is incrementing ticks2 (by 5) until it's > > CLOCKS_PER_SEC more than ticks1, modulo whatever ticks1 started at. > > You could have done this and gotten similar results: > > > > > ticks1=0 > > > ticks2=ticks1; > > > while((ticks2/CLOCKS_PER_SEC-ticks1/CLOCKS_PER_SEC)<1) > > > ticks2 += 5; > > > > Note that, because of the "* 5", the value you get could be off by as > > much as 4 due to the fact that clock() will *always* return a multiple > > of 5. However, the increment from one clock() to the next clock() is > > not always the *same* multiple of 5. > > > > Try using "< 100" instead of "< 1" in your code and see what happens. > > That will give you an average value, not one test value.