How to measure web page load round trip time / performance using Javascript

So you want to know how long it takes for your users to load your page in their browser?
You can do this with a little Javascript called round trip time ping I created.

Q: So how does it work?
A: Simple - just include the Javascript on each of your pages in the header with the following line:
<script type="text/javascript" src="/rtt_ping.js"></script>
The script will attach an event to every anchor link on your page and on click it will take a timestamp and store it in a cookie. Now when the next page loads (also including the script) upon finishing page loading it will try to read the cookie and if present calculate the difference from the time stamp.
The result is the time in milliseconds it takes from the moment of clicking until the moment when the new page finished loading. This result will be sent to a tracking pixel URL which will cause an entry in your web server access log (that you can later evaluate). Instead of a static transparent 1x1 tracking pixel gif you could also develop a script that counts the numbers to a DB directly.

Q: What are the pros and cons of this approach?
A:
Con: there is a small additional overhead you introduce by executing the extra script, sending the cookie, etc. - this may increase your page rendering time, but only insignificantly imho. Also it will measure the page when fully loaded by the browser, whereas the user "sees" most of the page a lot earlier and the perceived page loading time may actually be shorter. But onload is the best way to hook into, there is no other reliable way that works the same across all browsers (such as do this when all visible parts have been rendered).

Pro: the script measures the actual complete round trip time from the point of clicking, as experienced by the end user and his browser, on his internet connection, on his PC. This is important as it may be an altogether completely different experience from what you (the page creator) experience on your development machine on a big fat internet connection.

Other links:
Integration, how to do this with google analytics