Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

[OT] Re^2: Populating an array via a DBI call - simplified

by erix (Prior)
on Apr 01, 2017 at 12:55 UTC ( #1186683=note: print w/replies, xml ) Need Help??


in reply to Re: Populating an array via a DBI call - simplified
in thread Populating an array via a DBI call - simplified

Slightly [OT]...

my @names = $db->query('SELECT name FROM people WHERE id > 5')->flat;

I thought that looked nice so I had a look at it. But when compared to the 'normal' DBI way it turns out there is really not much of an advantage. The line is a little shorter (++) but you get a dependency (--) and lose quite a bit of speed (--).

perl -MData::Dumper -MDBI -MDBIx::Simple -e ' my $db1 = DBI->connect; # (uses defaults to connect) my $db2 = DBIx::Simple->connect; use Benchmark qw( cmpthese ) ; my $COUNT = -20; print "-- COUNT [$COUNT]\n"; cmpthese( $COUNT, { selectrow_arrayref => sub { my @arr = @{ $db1->selectrow_arrayref( + "select i from generate_series(1,10) as f(i) where i > 5" ) }; }, dbix_query_flat => sub { my @arr = $db2->query( "select i from +generate_series(1,10) as f(i) where i > 5")->flat; }, }); ' -- COUNT [-20] Rate dbix_query_flat selectrow_arrayref dbix_query_flat 5608/s -- -23% selectrow_arrayref 7293/s 30% --

As always when I look closer at ORMy things (mainly because many people seem to be fond of ORMs), I don't think it's worth it.

Replies are listed 'Best First'.
Re: [OT] Re^2: Populating an array via a DBI call - simplified
by ablanke (Parson) on Apr 02, 2017 at 12:08 UTC
    Hi erix,

    first of all ++ for your post. That are the choices you have to made.

    Slightly OT...

    Yes, i tried to see the OP from a different angle.

    As always when I look closer at ORMy things...

    I don't think it's too ORMy.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1186683]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-06-18 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (87 votes). Check out past polls.

    Notices?