Author |
Message |
Stephan Bergman #1 / 17
|
 time in milliseconds
Hi! How can I get a time in milliseconds, e.g. if Im searching in a file and later I want to say: "The objekt youre looking for has been found within 237 milliseconds"? Thanx and greetings Stephan
|
Tue, 21 Oct 2003 14:23:21 GMT |
|
 |
Zoran Cutur #2 / 17
|
 time in milliseconds
Quote: > Hi! > How can I get a time in milliseconds, e.g. if Im searching in > a file and later I want to say: "The objekt youre looking for > has been found within 237 milliseconds"?
The clock() function may be used for such things but your system/compiler may have some extra function handy that may have a better resollution. To get the time elapsed between to calls to clock() in seconds devide the difference with CLOCKS_PER_SEC. --
"LISP is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days." -- Eric S. Raymond
|
Tue, 21 Oct 2003 14:40:17 GMT |
|
 |
Lawrence Kir #3 / 17
|
 time in milliseconds
Quote:
>> Hi! >> How can I get a time in milliseconds, e.g. if Im searching in >> a file and later I want to say: "The objekt youre looking for >> has been found within 237 milliseconds"? >The clock() function may be used for such things but your
The clock() function measures CPU time used and not elapsed time so it may or may not be what is needed. For I/O operations probably not. It also has no guarantees concerning resolution, although it is sub-second on most implementations. Quote: >system/compiler may have some extra function handy that may >have a better resollution.
That is usually the best approach if you really need this sort of precision. -- -----------------------------------------
-----------------------------------------
|
Tue, 21 Oct 2003 22:01:14 GMT |
|
 |
Feng H #4 / 17
|
 time in milliseconds
Try ftime(). Feng Quote:
> >> Hi! > >> How can I get a time in milliseconds, e.g. if Im searching in > >> a file and later I want to say: "The objekt youre looking for > >> has been found within 237 milliseconds"? > >The clock() function may be used for such things but your > The clock() function measures CPU time used and not elapsed time so > it may or may not be what is needed. For I/O operations probably not. > It also has no guarantees concerning resolution, although it is > sub-second on most implementations. > >system/compiler may have some extra function handy that may > >have a better resollution. > That is usually the best approach if you really need this sort of > precision. > -- > -----------------------------------------
> -----------------------------------------
Feng He Swarthmore '03
|
Tue, 21 Oct 2003 22:39:12 GMT |
|
 |
vsat.. #5 / 17
|
 time in milliseconds
hi, If milli second precision is all what you need then you can look up the bios data area at 40:6ch both before and after your code and use the difference as a measure of the time taken. Alternately Turbo C++ offers a function clock() <time.h> which can be used as well. The problem here is that you can reach a precision of only 1/18.2 of a second as both rely on the System's RTC which counts 18.2 times a second. [ should be fairly enough for your file processing code.]. In assembly you can achieve micro-second accuracy by using the rdtsc (ReaD Time Stamp Counter) instruction provided by the pentium class of processors. Anything else ? Cheers.
|
Tue, 21 Oct 2003 23:25:02 GMT |
|
 |
Tobias Oe #6 / 17
|
 time in milliseconds
Quote:
> hi, > If milli second precision is all what you need then you > can look up the bios data area at 40:6ch > both before and after your code and use the difference > as a measure of the time taken. > Alternately Turbo C++ offers a function clock() <time.h> > which can be used as well. > The problem here is that you can reach a precision > of only 1/18.2 of a second as both rely on the System's RTC > which counts 18.2 times a second. > [ should be fairly enough for your file processing code.]. > In assembly you can achieve micro-second accuracy by using the > rdtsc (ReaD Time Stamp Counter) instruction provided by > the pentium class of processors. > Anything else ?
Yes: Don't post HTML to usenet. stay on topic. c.l.c. is for discussing programing in the c language. This guaranties portability of the code. Your suggestions are accurate for a given architecture only. Tobias.
|
Wed, 22 Oct 2003 00:04:35 GMT |
|
 |
CBFalcone #7 / 17
|
 time in milliseconds
Quote:
> Part 1.1 Type: Plain Text (text/plain) > Encoding: quoted-printable
illegible. Don't use html, mime, or attachments in newsgroups. --
http://www.qwikpages.com/backstreets/cbfalconer :=(down for now) (Remove "NOSPAM." from reply address. my-deja works unmodified)
|
Wed, 22 Oct 2003 02:27:08 GMT |
|
 |
Dan P #8 / 17
|
 time in milliseconds
Quote: >Try ftime().
How do you know there is such a thing on the OP's system? Or did they add this function to the standard while I wasn't looking? Get a clue! Dan -- Dan Pop CERN, IT Division
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
|
Wed, 22 Oct 2003 13:05:57 GMT |
|
 |
Dan P #9 / 17
|
 time in milliseconds
Quote:
>hi, > If milli second precision is all what you need then you > can look up the bios data area at 40:6ch
How do I do that on my Digital Unix workstation? Quote: > both before and after your code and use the difference > as a measure of the time taken. > Alternately Turbo C++ offers a function clock() <time.h> > which can be used as well.
Too bad it doesn't measure *real* time. Quote: > The problem here is that you can reach a precision > of only 1/18.2 of a second as both rely on the System's RTC > which counts 18.2 times a second.=20
I was under the misguided impression that my workstation's clock() implementation relies on the system's time slice, which happens to be 1/60 of a second. Oh well, one learns something new every day! Quote: > [ should be fairly enough for your file processing code.]. > In assembly you can achieve micro-second accuracy by using the > rdtsc (ReaD Time Stamp Counter) instruction provided by > the pentium class of processors.
How do you know the OP's system has a Pentium class processor? Mine certainly hasn't! Quote: > Anything else ?
Yup: this is comp.lang.c, a platform neutral newsgroup and the OP didn't make any mention about what kind of system(s) he's using or how portable the solution should be. So, your reply is pure bullshit, both in presentation and in contents. Dan -- Dan Pop CERN, IT Division
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
|
Wed, 22 Oct 2003 13:14:00 GMT |
|
 |
Tor Rusta #10 / 17
|
 time in milliseconds
Quote:
> > Hi! > > How can I get a time in milliseconds, e.g. if Im searching in > > a file and later I want to say: "The objekt youre looking for > > has been found within 237 milliseconds"? > The clock() function may be used for such things but your
Since clock() returns processor time used by current program, I assume this is not what OP want. Quote: > system/compiler may have some extra function handy that may > have a better resollution. > To get the time elapsed between to calls to clock() in seconds > devide the difference with CLOCKS_PER_SEC.
Well, time() is the standard function C provide for this. For higher resolution than seconds, OP need to use a system dependent function. -- Tor <torust AT online DOT no>
|
Wed, 22 Oct 2003 18:57:15 GMT |
|
 |
Dan P #11 / 17
|
 time in milliseconds
Quote: >Well, time() is the standard function C provide for this. For higher >resolution than seconds, OP need to use a system dependent function.
^^^^ The OP *may* need to use a system dependent function. There is nothing preventing time() from providing microsecond resolution. Dan -- Dan Pop CERN, IT Division
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
|
Thu, 23 Oct 2003 06:08:54 GMT |
|
 |
Lawrence Kir #12 / 17
|
 time in milliseconds
Quote:
>>Well, time() is the standard function C provide for this. For higher >>resolution than seconds, OP need to use a system dependent function. > ^^^^ >The OP *may* need to use a system dependent function. There is nothing >preventing time() from providing microsecond resolution.
Although either way it has to make use of a system dependent feature. -- -----------------------------------------
-----------------------------------------
|
Fri, 24 Oct 2003 03:36:35 GMT |
|
 |
Tor Rusta #13 / 17
|
 time in milliseconds
Quote:
> >Well, time() is the standard function C provide for this. For higher > >resolution than seconds, OP need to use a system dependent function. > ^^^^ > The OP *may* need to use a system dependent function. There is nothing > preventing time() from providing microsecond resolution.
Even so, that will not help OP much, unless you know a way to extract such information in a standard way. -- Tor <torust AT online DOT no>
|
Fri, 24 Oct 2003 03:38:40 GMT |
|
 |
Dan P #14 / 17
|
 time in milliseconds
Quote:
>> >Well, time() is the standard function C provide for this. For higher >> >resolution than seconds, OP need to use a system dependent function. >> ^^^^ >> The OP *may* need to use a system dependent function. There is nothing >> preventing time() from providing microsecond resolution. >Even so, that will not help OP much, unless you know a way to extract such >information in a standard way.
4.12.2.2 The difftime function Synopsis #include <time.h> double difftime(time_t time1, time_t time0); ^^^^^^ Description The difftime function computes the difference between two calendar times: time1 - time0 . Returns The difftime function returns the difference expressed in seconds as a double. ^^^^^^^^^^^ Is this standard enough for you? Dan -- Dan Pop CERN, IT Division
Mail: CERN - IT, Bat. 31 1-014, CH-1211 Geneve 23, Switzerland
|
Fri, 24 Oct 2003 22:48:19 GMT |
|
 |
Micah Cowa #15 / 17
|
 time in milliseconds
Quote:
> The difftime function returns the difference expressed in seconds
^^^^^^^^^^ Quote: > as a double. > ^^^^^^^^^^^ > Is this standard enough for you? > Dan
Is that far enough from an answer to the OP for you? Micah
|
Sat, 25 Oct 2003 01:06:38 GMT |
|
|