develooper Front page | perl.perl5.porters | Postings from December 2009

Re: Pod::Abstract 0.19 generating warnings on 5.11.3

Thread Previous | Thread Next
From:
Eric Brine
Date:
December 29, 2009 06:53
Subject:
Re: Pod::Abstract 0.19 generating warnings on 5.11.3
Message ID:
f86994700912290653h393f4615w7a1c0c664bf83f5c@mail.gmail.com
On Mon, Dec 28, 2009 at 1:34 PM, Aristotle Pagaltzis <pagaltzis@gmx.de>wrote:

> The `eval` is redundant. If you’re going to use `eval` you can
> just say this:
>
>    eval { return $val->isa($class) };
>    $class eq ref $val;
>
> But this is   s   l   o   w  .


It's no slower than the alternative you suggested

Positive tests
         Rate eval  can
eval 639402/s   --  -0%
can  641049/s   0%   --
Negative tests
         Rate eval  can
eval 791961/s   --  -2%
can  808965/s   2%   --

Test:

use strict;
use warnings;

use Benchmark qw( cmpthese );

{
    package Class::Base;
}

{
    package Class::Child;
    our @ISA = 'Class::Base';
}

sub isa_eval {
    my $val   = shift;
    my $class = shift;
    return eval { $val->isa($class) };
}

sub isa_can {
    my $val   = shift;
    my $class = shift;
    return UNIVERSAL::can( $val, 'can' ) && $val->isa( $class );
}

my %tests = (
    'eval' => 'my $isa = eval { $x->isa("Class::Base") };',
    'can'  => 'my $isa = UNIVERSAL::can($x, "can") &&
$x->isa("Class::Base");',
);

$_ = 'use strict; use warnings; our $x; ' . $_
    for values %tests;

{
    print("Positive tests\n");
    local our $x = bless({}, 'Class::Child');
    cmpthese(-3, \%tests);
}

{
    print("Negative tests\n");
    local our $x = bless({}, 'Foo::Bar');
    cmpthese(-3, \%tests);
}

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About