On Tue, Aug 14, 2001 at 10:33:31AM -0400, Yacketta, Ronald wrote:
> 
> Please be open and honest, I am looking to speed up the script and make it
> more efficient as well
> 
> sub get_oracle_time () {
> # Lets get the time it takes to connect to oracle
>       my ( $key, $value );
>         $oratime = qx(
> (timex sqlplus $RTDUSER/$RTDPASS\@RTD_ORACLE_SID <<-!>/dev/null
> quit
> !
> ) 2>&1);

Here you're spawning a shell to connect to the database using sqlplus.
How about use a DBI connection instead:




use Benchmark;
use DBI;

$oratime = timeit( 1,
        sub {
                 # Connect to the database.
                 my $dbh = DBI->connect( $ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
                    {RaiseError => 0, PrintError => 1} );
                die $DBI::errstr if $DBI::err;
                 # ... added error checking here
                 $dbh->disconnect if $dbh;
            } );
 
print "Connect/Disconnect : time: ", timestr( $oratime ), "\n";

# Connect/Disconnect : time:  0 wallclock secs ( 0.06 usr +  0.01 sys = 0.07 CPU) @ 
14.29/s (n=1)

# Or an example using Time::HiRes, taken mostly from perldoc
# Time::HiRes

use Time::HiRes qw( gettimeofday tv_interval );

# measure elapsed time
# (could also do by subtracting 2 gettimeofday return values)
my $t0 = [gettimeofday];

# Connect to the database.
my $dbh = DBI->connect( $ENV{DBI_DSN}, $ENV{DBI_USER}, $ENV{DBI_PASS},
   {RaiseError => 0, PrintError => 1} );
die $DBI::errstr if $DBI::err;
# ... added error checking here
$dbh->disconnect if $dbh;

$elapsed = tv_interval ($t0); # equivalent code

print "Connect/Disconnect : elapsed time: ", $elapsed, "\n";

# Connect/Disconnect : elapsed time: 0.095902 


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to