通过 Devel::NYTProf 运行我的脚本显示以下代码部分占用了绝大多数运行时间。该函数创建一个更易于使用的散列,并将该散列推入一个数组。我想知道如何在不花这么长时间的情况下做到这一点。
来自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;
}