Client's clocks are more precise (Java Script)

In the above example we always used the server's clock to measure the time. This adds noise to the observation. A more precise measurement can be obtained if we use the client's clock. The following example uses Java Script to measure the time between showing a page and submitting a form. This result is compared with the time difference on the server.

    function startClock () {
        timeA = new Date();
        return true;
    function stopClock () {
        timeB = new Date ();
        timeDifference = timeB - timeA;
        return true;
    $time=explode(" ",microtime());
    $serverDiff=$time - $serverTime;
    $networkDelay=$serverDiff - $tdiff;
    echo "<BODY onLoad=startClock()>'';
    if ($tdiff) echo "The time difference measured by the client is $tdiff milliseconds<P>
       The time difference measured by the server is $serverDiff milliseconds<P>
       The network delay is, hence, $networkDelay milliseconds<P>";
    echo "<FORM NAME=timeForm METHOD=POST ACTION=$SCRIPT_NAME onSubmit=stopClock()>
    <INPUT TYPE=HIDDEN NAME=serverTime VALUE=$time>

Oliver Kirchkamp 2013-04-15