In my Web application, I am loading the module dynamically at runtime by using the below code but looks like it is taking good amount of time that makes the application bit slower.
eval {
eval "require $package_name";
}
if ($@) {
die"Error while loading module: $@\n";
}
I made one small program to check that eval "require $package_name"; this piece of code taking how much time on an average, then I found that it is taking almost 10 seconds that is huge for web application.
use strict;
use Time::HiRes qw( gettimeofday tv_interval );
my $startTime = [ gettimeofday() ];
print "Time:@{$startTime}->[0]\n";
eval "require Foo::Bar"; # giving example
my $timeSpent = tv_interval( $startTime, [ gettimeofday() ] );
print "Time Spent:$timeSpent\n";
exit 1;
Output:
Time:1378897304
Time Spent:10.627147
So my question is that why this is taking so much time and Is there any alternative to resolve this?
eval. Justrequire Foo::Barwithout theevalwill probably take the same amount of time spent.