Aniki

 view release on metacpan or  search on metacpan

author/benchmark.pl  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use feature qw/say/;

use lib 'lib';
use SampleDbic::Schema;
use SampleAniki::DB;
use SampleAniki::DB::Schema;
use SampleTeng::DB;
use Benchmark qw/cmpthese timethese/;

my $aniki = SampleAniki::DB->new(connect_info => ["dbi:SQLite:dbname=:memory:", "", "", { ShowErrorStatement => 1 }]);
my $dbic = SampleDbic::Schema->connect('dbi:SQLite:dbname=:memory:');
my $teng = SampleTeng::DB->new({ connect_info => ["dbi:SQLite:dbname=:memory:", "", ""], sql_builder_args => { strict => 1 } });

$aniki->dbh->do($_) for split /;/, SampleAniki::DB::Schema->output;
$teng->dbh->do($_) for split /;/, SampleAniki::DB::Schema->output;
$dbic->storage->dbh->do($_) for split /;/, SampleAniki::DB::Schema->output;

say '=============== SCHEMA ===============';
print SampleAniki::DB::Schema->output;

say '=============== INSERT (no fetch) ===============';
my ($dbic_id, $teng_id, $aniki_id) = (0, 0, 0);
timethese 100000 => {
    aniki => sub {
        $aniki->insert('author' => {
            name => "name:".$aniki_id++,
        });
    },
};

$aniki->dbh->do('DELETE FROM author');
$aniki->dbh->do('DELETE FROM sqlite_sequence WHERE name = ?', undef, 'author');

say '=============== INSERT (fetch auto increment id only) ===============';
($dbic_id, $teng_id, $aniki_id) = (0, 0, 0);
cmpthese timethese 100000 => {
    teng => sub {
        my $id = $teng->fast_insert('author' => {
            name => "name:".$teng_id++,
        });
    },
    aniki => sub {
        my $id = $aniki->insert_and_fetch_id('author' => {
            name => "name:".$aniki_id++,
        });
    },
};

$aniki->dbh->do('DELETE FROM author');
$aniki->dbh->do('DELETE FROM sqlite_sequence WHERE name = ?', undef, 'author');
$teng->dbh->do('DELETE FROM author');
$teng->dbh->do('DELETE FROM sqlite_sequence WHERE name = ?', undef, 'author');

say '=============== INSERT ===============';
($dbic_id, $teng_id, $aniki_id) = (0, 0, 0);
cmpthese {
    %{
        timethese 20000 => {
            dbic => sub {
                my $row = $dbic->resultset('Author')->create({



( run in 2.318 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )