Question

I'm sometimes use the LWP::Simple Perl module, which I understand is a reduced version of the full LWP module. I use it blindly because somebody suggested i use it a while back. What is the benefit of using it over the full package, is it faster and is it easier to use?

Was it helpful?

Solution

LWP::Simple is not faster than LWP::UserAgent since it uses LWP::UserAgent. It's just a simpler interface.

OTHER TIPS

Questions of the "is A faster than B" sort, should always get the same answer: try it! In your environment, with the kind of data you generally use, etc. Here's a short script to get you started:

use strict;
use warnings;

use Benchmark qw/ cmpthese /;
use LWP::UserAgent;
use LWP::Simple;

my $url = 'http://localhost/';

my $ua = sub {
    my $ua = LWP::UserAgent->new;
    my $res = $ua->get( $url );
    if ( $res->is_success ) {
        my $content = $res->decoded_content;
    }
};

my $simple = sub {
    my $content = get( $url );
};

cmpthese( -60, {
        'LWP::UserAgent' => $ua,
        'LWP::Simple'    => $simple,
});

On my system, where http://localhost/ will return a tiny index page, LWP::Simple is actually slightly slower:

                Rate    LWP::Simple LWP::UserAgent
LWP::Simple    401/s             --            -3%
LWP::UserAgent 414/s             3%             --

But it's hard to tell what will haven, when the URL gives you a DVD image, e.g.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top