当我查看
Devel::NYTProf v4的输出为
CGI program,我遇到了诊断.pm在报告源代码文件 – 排序的时间,然后名称。
首先我不明白为什么会在生产代码。我深入挖掘报告,发现它被称为main :: BEGIN @ 17。反过来,这是,下面这一行:
# spent 34µs (26+8) within main::BEGIN@15 which was called: # once (26µs+8µs) by main::RUNTIME at line 15 use strict; # spent 34µs making 1 call to main::BEGIN@15 # spent 8µs making 1 call to strict::import # spent 36µs (17+19) within main::BEGIN@16 which was called: # once (17µs+19µs) by main::RUNTIME at line 16 use warnings; # spent 36µs making 1 call to main::BEGIN@16 # spent 19µs making 1 call to warnings::import # spent 292ms (171+121) within main::BEGIN@17 which was called: # once (171ms+121ms) by main::RUNTIME at line 17 no diagnostics; # spent 292ms making 1 call to main::BEGIN@17 # spent 135µs (27+108) within main::BEGIN@18 which was called: # once (27µs+108µs) by main::RUNTIME at line 18 use Carp qw( carp croak );
所以这似乎是罪魁祸首。我删除了无诊断线,呼叫去了,有效地节约了大约300ms的时间。
这里是perldoc use
说关于no关键字:
There’s a corresponding no declaration that unimports meanings
imported by use,i.e.,it calls unimport Module LIST instead of
import. It behaves just as import does with VERSION,an omitted or
empty LIST,or no unimport method being found.06001
所以这里是我的实际问题:我是否正确的假设,如果我调用没有诊断,它实际上加载之前,它被卸载?
BEGIN { require diagnostics.pm; diagnostics->unimport; }
因此,是不是一个坏主意,只是unimport的东西,从来没有被导入,因为实际上加载它首先?