[Tutor] Bandwidth Tester

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Apr 24 10:49:36 CEST 2005

On Sun, 24 Apr 2005, Ali Polatel wrote:

> How can i write a simple bandwidth tester with Python?

Hi Ali,

A really rough sketch would be:

###### Really rough pseudocode
def bandwidthTest():
    Record the current time (use time.time())
    Choose some resource that you can download, and download it
    Record the current time again.

By this time, you should have some file that has been downloaded, and
you'll know how long it took you to get that file: this is enough
information to get a rough bandwidth calculation.

To make it robust, you'll probably want to do this on several resources on
the web, and on ones that are reliably fast, and then average the results.
You might also have to take into account things like bad connections, or
perhaps servers going down.  So the real world makes things a little

If you'd like a real example of one that's in production use, see:


It's the bandwidth tester used by the Firefox project.  The source code is
in Javascript, and can be extracted by using 'jar' to unpack the .XPI

The source code in 'chrome/tester.js' doesn't look too particularly
daunting: the basic idea is the one sketched up above, with some special
cases to make sure silly things like Divide-by-zero don't happen.  And
it's slightly ugly because the interface / status-report code is mixed in
with the algorithm, but oh well.  *grin*

Best of wishes!

More information about the Tutor mailing list