Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.54 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use DBIx::Connector;
  3. use DBIx::Struct;
  4. use strict;
  5. use warnings;
  6.  
  7. # used this world database https://dev.mysql.com/doc/index-other.html
  8.  
  9. DBIx::Struct::connect( "DBI:mysql:database=world", "world", "world1" );
  10. my $connector =
  11.   DBIx::Connector->new( "DBI:mysql:database=world", "world", "world1",
  12.     { PrintError => 1, RaiseError => 1, mysql_enable_utf8 => 1 } );
  13.  
  14. use JSON;
  15. use Benchmark qw(:all);
  16. cmpthese(
  17.     -5,
  18.     {
  19.         'Struct' => sub {
  20.             my $cities = all_rows(
  21.                 [
  22.                     "city s" => -join => "country c" => -on => "s.CountryCode = c.Code" => -join =>
  23.                       "countrylanguage l" => -on => "l.CountryCode = c.Code",
  24.                     -columns => [ 's.Name city', 'c.Name country', 'Language language' ],
  25.                 ],
  26.                 -where => { Language => 'English' }
  27.             );
  28.         },
  29.         DBI => sub {
  30.             my $dbh_cities = $connector->run(
  31.                 sub {
  32.                     $_->selectall_arrayref(
  33.                         qq{select s.Name city, c.Name country, Language language from city s}
  34.                           . qq{ join country c on(s.CountryCode = c.Code) join countrylanguage l on(l.CountryCode = c.Code)}
  35.                           . qq{  WHERE ( Language = ? )},
  36.                         { Slice => {} },
  37.                         'English'
  38.                     );
  39.                 }
  40.             );
  41.         },
  42.     }
  43. );
  44. __END__
  45.         Rate Struct    DBI
  46. Struct 362/s     --   -40%
  47. DBI    604/s    67%     --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement