为什么Perl编译diagnostics.pm如果我的代码没有诊断?

前端之家收集整理的这篇文章主要介绍了为什么Perl编译diagnostics.pm如果我的代码没有诊断?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我查看 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的东西,从来没有被导入,因为实际上加载它首先?

解决方法

Am I correct in assuming that if I call no diagnostics,it is actually loaded before it is unimported?

是。它的确完全相当于

BEGIN {
  require diagnostics;
  diagnostics->unimport;
}

所以没有模块命令实际加载和编译模块;包括在BEGIN块等中执行不在任何子中的代码;对于给定模块的所有依赖性(对于每个使用/需求内部)是相同的。

原文链接:https://www.f2er.com/Perl/173264.html

猜你在找的Perl相关文章