Created
September 17, 2012 14:14
-
-
Save nihen/3737561 to your computer and use it in GitHub Desktop.
teng_vs_skinny
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ok 1 | |
ok 2 | |
ok 3 | |
ok 4 | |
ok 5 | |
ok 6 | |
ok 7 | |
1..7 | |
Teng version: 0.15 | |
Skinny version: 0.0742 | |
--- insert vs insert vs fast_insert --- | |
Rate Teng Skinny Teng_fast_insert | |
Teng 3378/s -- -48% -57% | |
Skinny 6494/s 92% -- -18% | |
Teng_fast_insert 7937/s 135% 22% -- | |
--- single vs single vs lookup --- | |
Rate Skinny Teng Teng_lookup | |
Skinny 4842/s -- -16% -42% | |
Teng 5743/s 19% -- -31% | |
Teng_lookup 8373/s 73% 46% -- | |
--- search vs search --- | |
Rate Skinny Teng | |
Skinny 1829/s -- -23% | |
Teng 2382/s 30% -- | |
--- search_by_sql vs search_by_sql --- | |
Rate Skinny Teng | |
Skinny 2133/s -- -21% | |
Teng 2715/s 27% -- | |
--- search_named vs search_named --- | |
Rate Skinny Teng | |
Skinny 2000/s -- -20% | |
Teng 2488/s 24% -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Benchmark qw(cmpthese); | |
use DBI; | |
use Test::More; | |
{ | |
package SKN; | |
use DBIx::Skinny; | |
package SKN::Schema; | |
use DBIx::Skinny::Schema; | |
install_table user => schema { | |
pk 'id'; | |
columns qw/id hoge/; | |
}; | |
package SKN::Row::User; | |
use parent 'DBIx::Skinny::Row'; | |
} | |
{ | |
package TNG; | |
use parent 'Teng'; | |
__PACKAGE__->load_plugin('Lookup'); | |
package TNG::Schema; | |
use Teng::Schema::Declare; | |
table { | |
name "user"; | |
pk "id"; | |
columns qw/id hoge/; | |
}; | |
} | |
my $table = 'create table user (id int primary key,hoge text)'; | |
my $skn = SKN->new; | |
$skn->set_dbh(DBI->connect('dbi:SQLite::memory:','','')); | |
$skn->do($table); | |
my $tng = TNG->new(dbh => DBI->connect('dbi:SQLite::memory:','','')); | |
$tng->do($table); | |
our $skn_user_id = 1; | |
our $tng_user_id = 1; | |
my $subs = { | |
'skinny' => { | |
insert => sub { | |
$skn->insert(user => { id => $skn_user_id++, hoge => 'moge' }) | |
}, | |
single => sub { | |
my $row = $skn->single(user => { id => 1 } ); | |
}, | |
search => sub { | |
my @row = $skn->search(user => {}, { limit => 20 }) | |
}, | |
search_by_sql => sub { | |
my @row = $skn->search_by_sql('select * from user limit 20') | |
}, | |
search_named => sub { | |
my @row = $skn->search_named('select * from user where id < :id limit 20', {id => 20}) | |
}, | |
}, | |
'teng' => { | |
insert => sub { | |
$tng->insert(user => { id => $tng_user_id++, hoge => 'moge' }) | |
}, | |
fast_insert => sub { | |
$tng->fast_insert(user => { id => $tng_user_id++, hoge => 'moge' }) | |
}, | |
single => sub { | |
my $row = $tng->single(user => { id => 1 } ); | |
}, | |
lookup => sub { | |
my $row = $tng->lookup(user => +{ id => 1 } ); | |
}, | |
search => sub { | |
my @row = $tng->search(user => {}, { limit => 20 }) | |
}, | |
search_by_sql => sub { | |
my @row = $tng->search_by_sql('select * from user limit 20') | |
}, | |
search_named => sub { | |
my @row = $tng->search_named('select * from user where id < :id limit 20', {id => 20}) | |
}, | |
}, | |
}; | |
is_deeply $subs->{skinny}{insert}->()->get_columns() => $subs->{teng}{insert}->()->get_columns(); | |
is $subs->{skinny}{insert}->()->id => $subs->{teng}{fast_insert}->(); | |
is_deeply $subs->{skinny}{single}->()->get_columns() => $subs->{teng}{single}->()->get_columns(); | |
is_deeply $subs->{skinny}{single}->()->get_columns() => $subs->{teng}{lookup}->()->get_columns(); | |
is_deeply [map {$_->get_columns} $subs->{skinny}{search}->()] => [map {$_->get_columns} $subs->{teng}{search}->()]; | |
is_deeply [map {$_->get_columns} $subs->{skinny}{search_by_sql}->()] => [map {$_->get_columns} $subs->{teng}{search_by_sql}->()]; | |
is_deeply [map {$_->get_columns} $subs->{skinny}{search_named}->()] => [map {$_->get_columns} $subs->{teng}{search_named}->()]; | |
done_testing(); | |
print "\n"; | |
print "Teng version: $Teng::VERSION\n"; | |
print "Skinny version: $DBIx::Skinny::VERSION\n"; | |
print "\n--- insert vs insert vs fast_insert ---\n"; | |
cmpthese(5000, { | |
'Skinny' => $subs->{skinny}{insert}, | |
'Teng' => $subs->{teng}{insert}, | |
'Teng_fast_insert' => $subs->{teng}{fast_insert}, | |
}); | |
$subs->{skinny}{insert}->() for (1..5000); | |
for my $method (qw/single search search_by_sql search_named/) { | |
my $adds = ''; | |
my @adds = (); | |
if ( $method eq 'single' ) { | |
$adds = 'vs lookup '; | |
@adds = ( | |
'Teng_lookup' => $subs->{teng}{lookup}, | |
); | |
} | |
print "\n--- $method vs $method $adds---\n"; | |
cmpthese(-1, { | |
'Skinny' => $subs->{skinny}{$method}, | |
'Teng' => $subs->{teng}{$method}, | |
@adds, | |
}); | |
} | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment