• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Filling in a struct timespec with the current date?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filling in a struct timespec with the current date?


  • Subject: Re: Filling in a struct timespec with the current date?
  • From: Esteban Bodigami <email@hidden>
  • Date: Wed, 29 Jul 2009 09:55:30 -0600

// Calculate the duration.

elapsed = end - start;

// Convert to nanoseconds.

// Have to do some pointer fun because AbsoluteToNanoseconds
// works in terms of UnsignedWide, which is a structure rather
// than a proper 64-bit integer.

elapsedNano = AbsoluteToNanoseconds( *(AbsoluteTime *) &elapsed );

return * (uint64_t *) &elapsedNano;


10−9 seconds and 10−8 seconds (1 ns and 10 ns)
103 seconds (a kilosecond)

1.440 ks to 1.500 ks = my "kilosecond"

3.600 kiloseconds = one hour

4.440 kiloseconds = 74 minutes (audio cd)

104 seconds = 1 myriad of seconds; 1 0000 s

/*
benchmark using the clock of your choice what the computer "sees" as 10^3 seconds and what one "sees" on the computer in... minutes.seconds (&SoD); everything else is margin of error (which should be recorded to enhance the software). 4.44 ks is more than 1 hour and 3.60 ks is exactly 1 "hour"
*/

> Or if he needs better resolution, mach_absolute_time(), which
> is well documented at <http://developer.apple.com>.

OK, the best documentation I've found for this is at
http://developer.apple.com/qa/qa2004/qa1398.html
and I whipped up a quick test program to ensure I knew what I was doing with it.  Now my question concerns accuracy; I know that mach_absolute_time() resolves to one nanosecond, but what is the accuracy?  Is there a way to tell what the accuracy is from the mach_timebase_info struct?  E.g., the greatest common denominator between numer and denom is the accuracy of the clock in nanoseconds?

This won't affect my current code, but I'd like to stick it into my own documentation so whenever I reuse this code I know what I'm getting in to.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Filling in a struct timespec with the current date? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)
 >Re: Filling in a struct timespec with the current date? (From: Jean-Daniel Dupas <email@hidden>)
 >RE: Filling in a struct timespec with the current date? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)
 >Re: Filling in a struct timespec with the current date? (From: Kevin Van Vechten <email@hidden>)
 >Re: Filling in a struct timespec with the current date? (From: Terry Lambert <email@hidden>)
 >RE: Filling in a struct timespec with the current date? (From: "Karan, Cem (Civ, ARL/CISD)" <email@hidden>)

  • Prev by Date: RE: Filling in a struct timespec with the current date?
  • Next by Date: Re: Filling in a struct timespec with the current date?
  • Previous by thread: RE: Filling in a struct timespec with the current date?
  • Next by thread: Re: Filling in a struct timespec with the current date?
  • Index(es):
    • Date
    • Thread