Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use DBIx::Connector;
- use DBIx::Struct;
- use strict;
- use warnings;
- # used this world database https://dev.mysql.com/doc/index-other.html
- DBIx::Struct::connect( "DBI:mysql:database=world", "world", "world1" );
- my $connector =
- DBIx::Connector->new( "DBI:mysql:database=world", "world", "world1",
- { PrintError => 1, RaiseError => 1, mysql_enable_utf8 => 1 } );
- use JSON;
- use Benchmark qw(:all);
- cmpthese(
- -5,
- {
- Struct => sub {
- my $cities = all_rows(
- [
- "city s" => -join => "country c" => -on => "s.CountryCode = c.Code" => -join =>
- "countrylanguage l" => -on => "l.CountryCode = c.Code",
- -columns => [ 's.Name city', 'c.Name country', 'Language language' ],
- ],
- -where => { Language => 'English' }
- );
- },
- StructNQ => sub {
- my $cities = all_rows(
- qq{select s.Name city, c.Name country, Language language from city s}
- . qq{ join country c on(s.CountryCode = c.Code) join countrylanguage l on(l.CountryCode = c.Code)},
- -where => { Language => 'English' }
- );
- },
- DBI => sub {
- my $dbh_cities = $connector->run(
- sub {
- $_->selectall_arrayref(
- qq{select s.Name city, c.Name country, Language language from city s}
- . qq{ join country c on(s.CountryCode = c.Code) join countrylanguage l on(l.CountryCode = c.Code)}
- . qq{ WHERE ( Language = ? )},
- { Slice => {} },
- 'English'
- );
- }
- );
- },
- }
- );
- __END__
- Rate StructNQ Struct DBI
- StructNQ 373/s -- -3% -42%
- Struct 383/s 3% -- -40%
- DBI 643/s 73% 68% --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement