Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Just a little update on my progress in case anyone is still interested ;)

I installed Class::DBI , and created an "Event" object to test with. The savings in the amount of code that I had to write was tremendous:

package Event; use base qw(Class::DBI); # Tell Class::DBI a little about yourself Event->table('events'); Event->columns('All', qw( name given_by location date time ) ); Event->columns('Primary', 'name'); Event->set_db('Main', 'dbi:mysql:xxx', 'xxx', 'xxx' ); 1;
But what I gain in simplicity, I lose a bit in performance:
#!/usr/bin/perl -w use DBI; use Guest; use Event; use Benchmark; # Connect to database my $dbh = DBI->connect( "dbi:mysql:web_stuff", 'xxx', 'xxx' ) or die "Can't connect to MySQL database: $DBI::errstr\n"; # Need to benchmark these solutions sub modify_event { ### Test (query) the Event object my $this_event = Event->retrieve('Party'); ### Test (modify) the Event object $this_event->time('9:00 PM'); $this_event->commit; } sub modify_guest { # Fetch One my $last_name = "Rodriguez"; my $q_last_name = $dbh->quote($last_name); my $first_names = "Alex"; my $q_first_names = $dbh->quote($first_names); my ($add,$city,$state,$zip,$cnt) = $dbh->selectrow_array( "SELECT address, city, state, zip, est_count FROM guest_list WHERE last_name = $q_last_name AND first_names = $q_first_names" ); my $guest = new Guest ($last_name,$first_names, $add,$city,$state,$zip,$cnt); #### Test Update $guest->state("TX"); $guest->update($dbh); } timethese(1000, {modify_event => 'modify_event()', modify_guest => 'modify_guest()' }); $dbh->disconnect(); exit;
Results:
Benchmark: timing 1000 iterations of modify_event, modify_guest... modify_event: 7 wallclock secs ( 5.25 usr + 0.26 sys = 5.51 CPU) modify_guest: 5 wallclock secs ( 2.89 usr + 0.15 sys = 3.04 CPU)

In reply to Re: Object Oriented Pattern help by thefid
in thread Object Oriented Pattern help by thefid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-04-26 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found