I have a weird question. After profiling my code several times with NYTProf. I have a slow piece of code that seems like it should be very fast?
if($my_var){
# spent 112s making 25764253 calls to DBI::st::fetch, avg 4µs/call
with the line taking 187sec to run? The code in the if statement does use bind variables, but $my_var is not one of them. And even if it is why?
Is the pro-filer just buggy and picking something else up? This statement is inside a
while($sth->fetch)
loop, but there is some code in between the 2 statements, and that code is fine. In fact all if statements inside the code seem unreasonably slow?
Just looking for any help I can get. I cant post the whole code. but some pseudo-code bellow:
use DBI;
my $dbh = <new mysql connection>;
my $sth = $dbh->prepare('SELECT A, B, C FROM D');
$sth->execute();
$sth->bind_columns(\my($a,$b,$c));
while($sth->fetch){
#do some fun stuff here.
my $d = $hash_lookup{$c} // 0;
if($d){
#do some more fun stuff here. This is where DBI::st::fetch is apparently being called?
}
}
Known bug:
Time spent evaluating a while condition can be misattributed to the last statement of the while loop.