• 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: Measuring latency
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Measuring latency


  • Subject: Re: Measuring latency
  • From: Matt Slot <email@hidden>
  • Date: Sun, 19 Oct 2008 11:36:58 -0400

On Oct 19, 2008, at 2:22 AM, Liwei wrote:
I need to have a way to measure latency in my application. My idea is
to send a "ping" message, take note of the current time and when the
return message arrives, find out how much time has elapsed to get the
round trip time and divide by two. This may not be terribly accurate
but should be sufficient for my use.

I've written an article on keeping network clocks in sync, which may provide some tips:


  http://www.codewhore.com/howto1.html

However, I can't seem to find a method of getting timing down to the
millisecond level. As far as I can find, CFAbsoluteTimeGetCurrent() is
the most precise way to get the current time, but only up to a second,
which isn't very useful for network latencies.

CFAbsoluteTimeGetCurrent() returns a double, with the fractional portion for finer resolution than seconds. However it returns the "wall clock" time, which is subject to NTP or user correction, making it unsuitable for measuring elapsed times.


You can use Microseconds() or the following replacement for CFAbsoluteTimeGetCurrent() to return an absolute timer that isn't erratic:

CFAbsoluteTime MyAbsoluteTimeGetCurrent()
{
	UnsignedWide wideNanoseconds = AbsoluteToNanoseconds(UpTime());
	return *(uint64_t *) &wideNanoseconds / (CFAbsoluteTime) 1000000000.0;
}

Matt Slot / Bitwise Operator / Ambrosia Software, Inc. -- http://www.AmbrosiaSW.com/

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Measuring latency (From: Liwei <email@hidden>)

  • Prev by Date: Re: Measuring latency
  • Next by Date: Not listen to your own broadcast
  • Previous by thread: Re: Measuring latency
  • Next by thread: Re: Measuring latency
  • Index(es):
    • Date
    • Thread