还可以尝试使用 Devel::DProf 来测试程序的性能,比如 CPAN 模块的里面关于 tar.gz 的处理模块的载入性能:

perl -d:DProf -MCPAN=shell -e 'shell'
dprofpp -g CPAN::Tarzip::BEGIN

只是输出的信息还值得仔细看看才能明白。

2009/2/13 Michael Zeng <[email protected]>

> thanks
>
>
>
> On 2/13/09, Shu Cho <[email protected]> wrote:
>>
>> 写了个简单的,见笑啦。
>>
>> # Timeit.pm
>> package Timeit;
>>
>> use strict;
>> use warnings;
>>
>> use Exporter;
>>
>> use base qw(Exporter);
>>
>> our $VERSION = 0.01;
>>
>> our @EXPORT_OK = qw(timeit);
>>
>> sub timeit {
>> my ($name, $code) = @_;
>>
>> my $now = time;
>>
>> if (ref $code eq 'CODE') {
>>    eval { $code->() };
>> }
>> else {
>>    eval $code;
>> }
>>
>> my $elapsed = time - $now;
>>
>> return sprintf("$name elapsed: %02d:%02d:%02d\n", int($elapsed / 3600),
>>                 int(($elapsed % 3600) / 60),
>>                 int($elapsed % 60));
>> }
>>
>> # test_timeit.pl
>> use strict;
>> use warnings;
>>
>> use Timeit qw(timeit);
>>
>> print timeit('sleep #1', sub { sleep 2; });
>> print timeit('sleep #2', "sleep 3");
>>
>> # output
>> sleep #1 elapsed: 00:00:02
>> sleep #2 elapsed: 00:00:03
>>
>> 2009/2/13 Michael Zeng <[email protected]>:
>> > 比如 我要计算这个脚本/程序花了多少时间
>> >
>> > 但是Benchmark 计算的结果都是以  XX  wall clock  seconds 来计算的
>> >
>> > 有没有 计算出 得到以  $hour:$min:$seconds  为格式的?
>> >
>> >
>> > --
>> >             Yours Sincerely
>> >                     Zeng Hong
>> > >
>> >
>>
>>
>> --
>>             Yours Sincerely
>>                     Zeng Hong
>> >>
>>

--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛“PerlChina Mongers 讨论组”论坛。
 要在此论坛发帖,请发电子邮件到 [email protected]
 要退订此论坛,请发邮件至 [email protected]
 更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---

回复