Commit | Line | Data |
f54428ab |
1 | #!/usr/bin/env perl |
caca5e19 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
5f9c6cda |
6 | use Benchmark qw/cmpthese/; |
caca5e19 |
7 | use FindBin; |
8 | use lib "$FindBin::Bin/../t/lib"; |
9 | use lib "$FindBin::Bin/../lib"; |
5f9c6cda |
10 | use DBICTest::Schema; |
21374921 |
11 | use DBIx::Class::ResultClass::HashRefInflator; # older dbic didn't load it |
12 | |
13 | printf "Benchmarking DBIC version %s\n", DBIx::Class->VERSION; |
caca5e19 |
14 | |
5f9c6cda |
15 | my $schema = DBICTest::Schema->connect ('dbi:SQLite::memory:'); |
16 | $schema->deploy; |
17 | |
caca5e19 |
18 | my $rs = $schema->resultset ('Artist'); |
21374921 |
19 | $rs->populate ([ map { { name => "Art_$_"} } (1 .. 10000) ]); |
caca5e19 |
20 | |
5f9c6cda |
21 | my $dbh = $schema->storage->dbh; |
22 | my $sql = sprintf ('SELECT %s FROM %s %s', |
23 | join (',', @{$rs->_resolved_attrs->{select}} ), |
24 | $rs->result_source->name, |
25 | $rs->_resolved_attrs->{alias}, |
26 | ); |
27 | |
28 | my $compdbi = sub { |
29 | my @r = $schema->storage->dbh->selectall_arrayref ('SELECT * FROM ' . ${$rs->as_query}->[0] ) |
30 | } if $rs->can ('as_query'); |
caca5e19 |
31 | |
5f9c6cda |
32 | cmpthese(-3, { |
33 | Cursor => sub { $rs->reset; my @r = $rs->cursor->all }, |
34 | HRI => sub { $rs->reset; my @r = $rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' } )->all }, |
35 | RowObj => sub { $rs->reset; my @r = $rs->all }, |
36 | RawDBI => sub { my @r = $dbh->selectall_arrayref ($sql) }, |
37 | $compdbi ? (CompDBI => $compdbi) : (), |
caca5e19 |
38 | }); |