delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2013/07/07/16:15:19

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
X-Received: by 10.224.55.200 with SMTP id v8mr21743527qag.7.1373227141627;
Sun, 07 Jul 2013 12:59:01 -0700 (PDT)
X-Received: by 10.50.9.7 with SMTP id v7mr2248653iga.2.1373227141587; Sun, 07
Jul 2013 12:59:01 -0700 (PDT)
Newsgroups: comp.os.msdos.djgpp
Date: Sun, 7 Jul 2013 12:59:01 -0700 (PDT)
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
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fd60497c-48ca-47ee-aefa-191f026fd3c1@googlegroups.com>
Subject: CLOCKS_PER_SEC of time.h doesn't work to prove it is a value for one second
From: "K.J.Williams" <lordwilliams1972 AT gmail DOT com>
Injection-Date: Sun, 07 Jul 2013 19:59:01 +0000
Bytes: 2725
Lines: 61
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id r67KF3uE032127
Reply-To: djgpp AT delorie DOT com

I tried a program that I found on the internet which calculates how many CLOCKS_PER_SEC are in one second. I compiled and ran the program on two different computers but got the same result. Then I took a look at time.h and found how CLOCKS_PER_SEC was implemented for DJGPP (I added this as a comment in the code code). I posted this code here because CLOCKS_PER_SEC is implementation defined stated by the ISO C standard. 


The original source code is from : 

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.15.html#variables

see "2.15.3 clock"


heres my file: clocks_1.c  

#include<time.h>
#include<stdio.h>

/*

a documentation note in DJGPP's time.h file states:

   65536(tics/hour) / 3600(sec/hour) * 5(scale) = 91.02
   The 5 is to make it a whole number (18.2*5=91) so that
   floating point ops aren't required to use it.

#define CLOCKS_PER_SEC 91

*/



int main(void)
{
  clock_t ticks1, ticks2;

  ticks1=clock();
  ticks2=ticks1;
  while((ticks2/CLOCKS_PER_SEC-ticks1/CLOCKS_PER_SEC)<1)
    ticks2=clock();

  printf("Took %ld ticks to wait one second.\n",ticks2-ticks1);
  printf("This value should be the same as CLOCKS_PER_SEC which is %ld.\n",CLOCKS_PER_SEC);
  return 0;
}

(eof)

Output ( binary tested on two different PC computers ):

Took 95 ticks to wait one second.
This value should be the same as CLOCKS_PER_SEC which is 91.

So... 95 ticks is not equal to CLOCKS_PER_SEC. Is the documentation note in 
time.h a using a correct calculation to determine CLOCKS_PER_SEC's value?   

Thanks

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019