daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Oct 17th, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         StructNQ => sub {
  30.             my $cities = all_rows(
  31.                 qq{select s.Name city, c.Name country, Language language from city s}
  32.                   . qq{ join country c on(s.CountryCode = c.Code) join countrylanguage l on(l.CountryCode = c.Code)},
  33.                 -where => { Language => 'English' }
  34.             );
  35.         },
  36.         DBI => sub {
  37.             my $dbh_cities = $connector->run(
  38.                 sub {
  39.                     $_->selectall_arrayref(
  40.                         qq{select s.Name city, c.Name country, Language language from city s}
  41.                           . qq{ join country c on(s.CountryCode = c.Code) join countrylanguage l on(l.CountryCode = c.Code)}
  42.                           . qq{  WHERE ( Language = ? )},
  43.                         { Slice => {} },
  44.                         'English'
  45.                     );
  46.                 }
  47.             );
  48.         },
  49.     }
  50. );
  51. __END__
  52.           Rate StructNQ   Struct      DBI
  53. StructNQ 373/s       --      -3%     -42%
  54. Struct   383/s       3%       --     -40%
  55. DBI      643/s      73%      68%       --
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top