Refactor insert logic (Row should not handle SQLA options)
[dbsrgits/DBIx-Class.git] / maint / benchmark_datafetch.pl
CommitLineData
f54428ab 1#!/usr/bin/env perl
caca5e19 2
3use strict;
4use warnings;
5
5f9c6cda 6use Benchmark qw/cmpthese/;
caca5e19 7use FindBin;
8use lib "$FindBin::Bin/../t/lib";
9use lib "$FindBin::Bin/../lib";
5f9c6cda 10use DBICTest::Schema;
21374921 11use DBIx::Class::ResultClass::HashRefInflator; # older dbic didn't load it
12
13printf "Benchmarking DBIC version %s\n", DBIx::Class->VERSION;
caca5e19 14
5f9c6cda 15my $schema = DBICTest::Schema->connect ('dbi:SQLite::memory:');
16$schema->deploy;
17
caca5e19 18my $rs = $schema->resultset ('Artist');
21374921 19$rs->populate ([ map { { name => "Art_$_"} } (1 .. 10000) ]);
caca5e19 20
5f9c6cda 21my $dbh = $schema->storage->dbh;
22my $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
28my $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 32cmpthese(-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});