Kaustubh has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I am using the following Packages to scrap WebPages:-
use WWW::Mechanize;
use WWW::Mechanize::TreeBuilder;
I am using a get method to get the url.I print LocalTime before using Get Method and then again I print the LocalTime after Get Method.I find a Time difference of 3 secs.
Is there any way to reduce this time difference?Say from 3 secs to 1 or 1.5 secs?

use strict; use warnings; use WWW::Mechanize; use WWW::Mechanize::TreeBuilder; my $mech = WWW::Mechanize->new; WWW::Mechanize::TreeBuilder->meta->apply($mech); my $datestring = localtime(); print "Local date and time before get method $datestring\n"; $mech->get( "http://www.xxx.com/p/1234" ); $datestring = localtime(); print "Local date and time after get method $datestring\n";

Following is the output of above code:-
Local date and time before get Wed Aug 17 13:32:19 2016 Local date and time after get Wed Aug 17 13:32:22 2016

Replies are listed 'Best First'.
Re: Reduction in Processing Time of Get Method
by Corion (Patriarch) on Aug 17, 2016 at 09:05 UTC

    You are aware that this time is out of your control and is the time it takes for your network connection to the remote end and for the server there to respond?

    If you have only this one request, there is no way to make it twice as fast, except buying a faster network connection and buying the remote end better hardware.

    If you have multiple URLs to fetch, you can launch multiple requests in parallel. See Parallel::ForkManager or maybe AnyEvent::HTTP or Future.

      Hi Corion,
      Thanks for your suggestion.

Re: Reduction in Processing Time of Get Method
by hippo (Archbishop) on Aug 17, 2016 at 09:04 UTC
    Is there any way to reduce this time difference?

    That will likely depend heavily on http://www.xxx.com/p/1234. How long does it take with a trivial URL (eg. this one? With a localhost URL? Without TreeBuilder?

    Once you know where the problem actually lies you can try to tackle it. See Debugging and Optimization for more clues.

      Hi Hippo,
      Thanks for your suggestions!The time difference varries if the URL is changed.

        If the same content from a different URL (eg. a localhost copy) takes much less time, then the network is clearly the bottleneck and unless you want to start getting into caching or have some control over the network then you are very much stuck with it.