Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #94848

Re: CLOCKS_PER_SEC

From BartC <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: CLOCKS_PER_SEC
Date 2016-10-13 23:30 +0100
Organization A noiseless patient Spider
Message-ID <ntp1uj$jki$1@dont-email.me> (permalink)
References <nto3cm$ps$1@dont-email.me> <lnr37kjl7y.fsf@kst-u.example.com> <lnmvi8jkq4.fsf@kst-u.example.com> <ntp16j$h6u$1@dont-email.me>

Show all headers | View raw


On 13/10/2016 23:18, BartC wrote:
> On 13/10/2016 17:07, Keith Thompson wrote:

> I think I will try and detect Windows or Linux and assume 1000 or
> 1000000 respectively. Doing that would also require invocating a C
> compiler on something like '#ifdef WIN32', but I think I will try a
> quick and dirty method like detecting the existence of some known .exe
> file in C:/windows.

The following seems to work! It's expressed here in C but only depends 
on standard fopen/fclose functions which can be called from anywhere.

I assume of course that it's always 1000 on Windows and 1000000 on 
Linux, but that might be enough (I think one compiler used to use 100). 
It's only for timing so it's not critical.


#include <stdio.h>
#include <stdlib.h>

int getclockspersec(void){
FILE *f;
if (f = fopen("c:/windows/notepad.exe","rb")) {
|   fclose(f);
|   return 1000;
}
return 1000000;
}

int main(int n, char** s) {

printf("%d\n",getclockspersec());

}

-- 
Bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-13 14:49 +0100
  Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 08:57 -0700
    Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 09:07 -0700
      Re: CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-13 23:18 +0100
        Re: CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-13 23:30 +0100
          Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 16:27 -0700
            Re: CLOCKS_PER_SEC raltbos@xs4all.nl (Richard Bos) - 2016-10-16 10:02 +0000
              Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-16 11:32 -0700
    Re: CLOCKS_PER_SEC Lowell Gilbert <lgusenet@be-well.ilk.org> - 2016-10-13 12:19 -0400
      Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 11:29 -0700
        Re: CLOCKS_PER_SEC Lowell Gilbert <lgusenet@be-well.ilk.org> - 2016-10-13 14:39 -0400
          Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-13 12:03 -0700
        Re: CLOCKS_PER_SEC supercat@casperkitty.com - 2016-10-14 07:47 -0700
  Re: CLOCKS_PER_SEC Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-10-14 16:21 +0300
    Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-14 08:41 -0700
      Re: CLOCKS_PER_SEC Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-10-14 18:56 +0300
        Re: CLOCKS_PER_SEC Barry Schwarz <schwarzb@dqel.com> - 2016-10-14 09:49 -0700
        Re: CLOCKS_PER_SEC Keith Thompson <kst-u@mib.org> - 2016-10-14 11:14 -0700
          Re: CLOCKS_PER_SEC supercat@casperkitty.com - 2016-10-14 11:32 -0700
      Re: CLOCKS_PER_SEC Jerry Stuckle <jstucklex@attglobal.net> - 2016-10-14 11:56 -0400
        Re: CLOCKS_PER_SEC Anton Shepelev <anton.txt@g{oogle}mail.com> - 2016-10-14 19:53 +0300
          Re: CLOCKS_PER_SEC supercat@casperkitty.com - 2016-10-14 09:57 -0700
          Re: CLOCKS_PER_SEC BartC <bc@freeuk.com> - 2016-10-14 18:18 +0100
        Re: CLOCKS_PER_SEC Malcolm McLean <malcolm.mclean5@btinternet.com> - 2016-10-16 02:55 -0700

csiph-web