我如何在执行的各个阶段进行 Perl CGI 性能测量、基准测试、时间测量?
我想知道用于测量 CGI Perl 代码在各个阶段的执行持续时间的技术(编码、库、配置):
- 启动 Perl 解释器
- 开始运行 Perl 代码
- 加载到本地 Perl .pm 模块中以
- 完成运行代码的
例程我对 3 和 4 特别感兴趣,我不认为我可以对 1) 或 2) 做太多事情,因为我不想尝试优化 Perl 解释器,我在这里唯一能做的就是升级将硬件升级到更快的机器和/或使用 mod_perl 而不是经典的 CGI。
3)加载本地 Perl 模块我想测量需要多长时间,但我不确定如何编码,因为我不知道(或不确定)如何在加载这些模块之前执行代码。如果我确实知道,那么我会记录它们加载之前的时间,然后记录它们加载后的时间并计算差异。
4)应该是最容易获得的,因为我会在执行开始时和结束时记录时间(在变量中)。
我在 stackoverflow.com 上进行了搜索,发现:
- 我该如何加速我的 Perl 程序? - 这是我期望在某个时候使用的。但我需要证明减少的时间(即速度的提高,所以我需要能够首先进行测量)。该工具 http://search.cpan.org/dist/Devel-NYTProf 看起来对于分析我的源代码很有用,但我不确定它涵盖了 3) 模块的加载
- Perl 语言的目标是在运行时生成快速程序吗? - 更多的是冗长的讨论而不是简洁的答案,但稍后当
Google 搜索结果包含时值得一读:
I would like to know techniques (coding, libraries, configurations) for measuring the duration of execution of CGI Perl code at various stages:
- starting up the Perl interpreter
- beginning running the Perl code
- loading in local Perl .pm modules for routines
- completed running the code
I'm particularly interested in 3 and 4, I don't believe there is much I can do about 1) or 2) as I wouldn't want to try to optimise the Perl interpreter, the only thing I can do here is upgrade the hardware to a faster machine and/or use mod_perl instead of classic CGI.
With 3) loading the local Perl modules I would like to measure how long it takes but I'm not sure how to code this as I don't know (or am not sure) how to get code to execute before loading these modules. If I did know, then I would record the time before they load, then record the time after they have loaded and calculate the difference.
4) should be the easiest to obtain as I would record the time (in a variable) at start of execution and then at end.
I've done a search at stackoverflow.com and found:
- How can I speed up my Perl program? - which is what I expect to be using at some point. BUT I need to prove the reduced time (i.e. speed improvement, so I need to be able to measure in the first place). The tool http://search.cpan.org/dist/Devel-NYTProf looks useful for profiling my source code but I'm not sure it covers 3) loading of modules
- Does Perl language aim at producing fast programs at runtime? - more of a verbose discussion rather than succinct answers, but a good read later when time
Google search results included:
- http://www.testingreflections.com/node/view/3622 - not enough information here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 FastCGI 减少 1)。它还将减少第 2) 和 3) 阶段。
对于测量 3),您可以使用 BEGIN 块。示例:
Deve::NYTProf 将帮助您完成 4)。还有一些特定的模块,如 Template::Timer、CGI::Application::Plugin::DevPopup::Timing、DBIx::Class::Storage::Statistics。
You can reduce 1) with FastCGI. It will reduce stages 2) and 3) too.
For measuring 3) you can use BEGIN blocks. Example:
Deve::NYTProf will help you with 4). Also there are specific modules like Template::Timer, CGI::Application::Plugin::DevPopup::Timing, DBIx::Class::Storage::Statistics.
除了FastCGI之外,还有mod_perl,更重要的是PSGI。使用 PSGI,您可以将应用程序与具体的网络服务器后端分离。
In addition to FastCGI, there is also mod_perl and more importantly PSGI. With PSGI you can decouple your app from concrete webserver backend.