True but LWP::UserAgent is slower than some other methods probably (as already said) down to its flexibility. Not that I am recommending HTTP::Lite (in fact HTTP::Lite pod says use LWP) but to retrieve a file on our local network with LWP::UserAgent and HTTP::Lite where I know it is UTF-8 encoded (so simplified) I get:

use 5.010; use strict; use warnings; use Benchmark; use Encode; use HTTP::Lite; use LWP::UserAgent; my $url = 'xxx.yyy.zzz/file.dat'; sub http_lite { my $r = HTTP::Lite->new; my $sts = $r->request($url); die "failed" if $sts != 200; my $decoded = Encode::decode('utf8', $r->body, Encode::FB_CROAK); } sub lwp_useragent{ my $ua = LWP::UserAgent->new; my $r = $ua->get($url); die "failed" if !$r->is_success; my $body = $r->decoded_content; } timethese(1000, { 'lite' => sub{http_lite()}, 'lwp' => sub{lwp_useragent()} }); Benchmark: timing 1000 iterations of lite, lwp... lite: 3 wallclock secs ( 1.53 usr + 0.60 sys = 2.13 CPU) @ 46 +9.48/s (n=1000) lwp: 6 wallclock secs ( 4.19 usr + 0.58 sys = 4.77 CPU) @ 20 +9.64/s (n=1000)

As I said, I'm not recommending HTTP::Lite just pointing out the difference in a simple case. It does not do HTTPS and defaults to HTTP 1.0 etc and maybe there is something else I've forgotten in the above example that LWP::UserAgent is doing that the HTTP::Lite sub is not.


In reply to Re^2: Why is LWP::UserAgent so slow? by mje
in thread Why is LWP::UserAgent so slow? by smetj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.