Running my script through Devel::NYTProf showed that the following portion of code took up the vast majority of running time. The function creates a hash that’s easier to work with, and that hash gets pushed into an array. I’m wondering how this can be done without taking as long as it does.
From Devel::NYTProf:
# Statements | Time on line | Calls | Time in sub
21092 16.4s 21092 273s push( @events, { create_events_hash($1, $2, $j, @eventHash) } );
# spent 273s making 21092 calls to Parser::create_events_hash, avg 12.9ms/call
# ...
# spent 273s (268+4.95) within Parser::create_events_hash which was called 21092 times,
avg 12.9ms/call: # 21092 times (268s+4.95s) by
Parser::findNewMessages at line 86, avg 12.9ms/call
# Statements | Time on line
sub create_events_hash {
21092 159s my ( $dateIndex, $msgIDIndex, $eventHashIndex, @eventHash ) = @_;
21092 81.8ms my %holder;
21092 137ms $holder{ID} = $eventHashIndex;
21092 190ms $holder{msgDate} = $dateIndex;
21092 243ms $holder{ReceivedAt} = $eventHash[$eventHashIndex]{ReceivedAt};
21092 181ms $holder{msgID} = $msgIDIndex;
21092 193ms $holder{FromHost} = $eventHash[$eventHashIndex]{FromHost};
21092 187ms $holder{Priority} = $eventHash[$eventHashIndex]{Priority};
21092 97.6s return %holder;
}
For starters, I’d send @eventhash as reference.
It is more effecient this way as it won’t make a copy of the array.