Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Object Oriented Pattern help

by thefid (Friar)
on May 14, 2001 at 05:45 UTC ( [id://80128]=note: print w/replies, xml ) Need Help??


in reply to Object Oriented Pattern 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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://80128]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-19 02:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found