Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] timing for geeks II.
- Date: Tue, 6 Dec 2005 09:27:34 +0100
- From: Michal Hajek <hajek1@example.com>
- Subject: Re: [tlug] timing for geeks II.
- References: <20051202154627.GB4348@example.com> <20051202152527.302e2f6f.jep200404@example.com> <20051203122655.GG4348@example.com> <20051203092314.3118db01.jep200404@example.com> <20051204100726.GH4348@example.com> <30ce84360512040313l351f16c4r1872cb4f6f34679e@example.com>
- User-agent: Mutt/1.5.9i
Hello :) Having cleared the issue with printf() :) and ftime() vs. gettimeofday(), I would like to make a step further and address the problem of gettimeofday() vs. clock_gettime() and, perhaps separately, clock_getres(). Of course, Ian Wells was writing about this all the time, unfortunatly, I was bussy with printf() (sorry). : * Ian Wells (ijw@example.com) [051203 14:50]: >Reading the man pages, the CLOCK_MONOTONIC clock seems best suited to >what you're doing. The other one can, in theory, get changed during >your process's execution. Ditto gettimeofday. This would be bad if >you're running NTP... * Ian Wells (ijw@example.com) [051204 12:28]: > The 'right', if less portable, answer, is the CLOCK_MONOTONIC clock, as ntp > (for example) will screw up gettimeofday. gettimeofday can go backwards if > something tampers at the wrong moment. So to test CLOCK_MONOTONIC vs. CLOCK_REALTIME with clock_getres(), I used this code (called rolex later on): #include <stdio.h> #include <stdlib.h> #include <time.h> main(int argc, char *argv[]) { struct timespec ts; clock_getres(CLOCK_MONOTONIC, &ts); printf("Clock resolution with CLOCK_MONOTONIC: %d.%09ld\n", (int)ts.tv_sec, (long int)ts.tv_nsec); clock_getres(CLOCK_REALTIME, &ts); printf("Clock resolution with CLOCK_REALTIME: %d.%09ld\n", (int)ts.tv_sec, (long int)ts.tv_nsec); return EXIT_SUCCESS; } Compiled with: gcc -Wall -o rolex rolex.c -lrt The output on gentoo (Gentoo Base System version 1.6.13): $ ./rolex Clock resolution with CLOCK_MONOTONIC: 715918496.2147481924 Clock resolution with CLOCK_REALTIME: 0.010000000 $ gcc --version gcc (GCC) 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8) The output on i386 debian (stable): $ ./rolex Clock resolution with CLOCK_MONOTONIC: 1073833280.-1073744028 Clock resolution with CLOCK_REALTIME: 0.010000000 $ gcc --version gcc (GCC) 3.3.5 (Debian 1:3.3.5-13) BUT: The output on amd64 debian (testing): $ ./rolex Clock resolution with CLOCK_MONOTONIC: 0.000999848 Clock resolution with CLOCK_REALTIME: 0.000999848 $ gcc --version gcc (GCC) 4.0.2 (Debian 4.0.2-2) I am going to make more tests in a few days and post it here. I plan to use clock_gettime() to write time for a moment and than compare the results for CLOCK_MONOTONIC and CLOCK_REALTIME. Best regards Michal :)
- Follow-Ups:
- Re: [tlug] timing for geeks II.
- From: Ian Wells
- Re: [tlug] It's time_t to Party!
- From: Jim
- Re: [tlug] timing for geeks II.
- From: Michal Hajek
- References:
- [tlug] timing for geeks :)
- From: Michal Hajek
- Re: [tlug] timing for geeks
- From: Jim
- Re: [tlug] timing for geeks
- From: Michal Hajek
- Re: [tlug] A Rich Experiment Indeed
- From: Jim
- Re: [tlug] A Rich Experiment Indeed
- From: Michal Hajek
- Re: [tlug] A Rich Experiment Indeed
- From: Ian Wells
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] "UTF-8 & ISO-2022-JP"
- Next by Date: Re: [tlug] TLUG List Archives
- Previous by thread: Re: [tlug] A Rich Experiment Indeed
- Next by thread: Re: [tlug] timing for geeks II.
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links