View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Augusto Ciuffoletti > Time-Skew-0.1 > Time::Skew



Annotate this POD

View/Report Bugs
Module Version: 0.1   Source  


Time::Skew - Computes local clock skew with respect to a remote clock.


  use Time::Skew

  # Init Convex Hull and timing data
  my $hull=[];
  my $result={};

  # Iterate data point introduction


This module supports the computation of the skew between two clocks: the (relative) skew is the speed with which two clocks diverge. For instance, if yesterday two clocks, at the same time, showed respectively 10:00 and 10:05, while today when the former shows 10:00 the latter shows 10:04, we say that their relative skew is 1 minute/24 hours, roughly 7E-4.

The module contains one single subroutine, which accepts as input a pair of timestamps, associated to a message from host A to host B: the timestamps correspond to the time when the message was sent, and to the time when message is received. Each timestamp reflects the value of the local clock where the operation takes place: the clock of host A for the send, the clock of B for the receive.

Please note that the module does _not_ contain any message exchange facility, but only the mathematics needed to perform the skew approximation, once timestamps are known.

The subroutine takes as argument:

The usage is very simple, and is illustrated by the following example:

 #!/usr/bin/perl -w
 use strict;
 use Time::Skew;

 # Initialize data
 my $hull=[];
 my $result={};
 while ( 1 ) {
 # Exchange message and acquire a new data point
   my $datapoint = acquire();
 # Call the convexhull subroutine
 # After first message some results are still undefined
   ( defined $result->{skewjitter} ) || next;
 # here you can use the results


The data returned in the "result" hash is the following:

The data returned in the "hull" stack is a series of data points, selected from those passed to successive calls of the subroutine. The number of data points in the "hull" stack usually does not exceed 20 units.

The algorithm is very fast: each call consists in scanning at most all data points in the "hull" stack, performing simple arithmetic operations for each element.

The algorithm must be fed with a sequence of data points before returning significant results. The accuracy of the estimate keeps growing while new data points are passed to the subroutine. A rough rule of thumb to evaluate estimate accuracy is to observe the skew jitter, and assume it corresponds to the skew estimate accuracy. Paths with quite regular communication delay (small jitter) converge faster.


0.1 Original version


A rounding problem may cause an inconsistent negative number of magnitude E-15 as "delay", instead of 0. A warning is generated, and the algorithm compensates the problem.



Augusto Ciuffoletti, <>


Copyright (C) 2005 by Augusto Ciuffoletti

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: