magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 2001 > 07 > Programming with Perl  

Calculating Download Time

By Randal L. Schwartz

It's a simple problem, really. You click on a link to a site. The site starts loading, but you're on a slow modem dialup. So it keeps loading, and loading, and loading. And the little icon in the upper right of your browser continues its animation as if that will keep you from noticing that the page still hasn't finished loading. Finally, just when you're about to hit "stop," it's done.

Why are these pages so big? Why are most pages so unfriendly to slow connections? I suspect it's because most pages are being designed within corporations that have T1 lines, and nobody ever bothers to test the pages from their home ISP connection. And that's unfortunate.

It would be fairly simple to write a test program that downloads the entire page, with all of its links, and reports how many bytes and how much time it takes to satisfy the browser. Of course, the program would have to go through all of the HTML looking for embedded images, sounds, objects (like Flash), and frame links. Hmm, sounds like a lot of work unless you have the right tools, like Perl's wonderful LWP library. With this in mind, I wrote such a program, and it's shown in Listing 1.

Line 1 turns on warnings a good thing to have while developing. Line 2 enables the common compiler restrictions, forcing us to declare our variables, and avoid the use of barewords and symbolic references. Line 3 enables autoflushing on STDOUT, so each line of output will be immediately visible as it's printed.




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2