2010年4月1日星期四

[PerlChina] Re: time函数在cygwin下面有bug?

Time::HiRes呈现更加怪异:

downloading http://london1.linode.com/100MB-london.bin 100MB-london.bin
1270111030.61801        1270111030
http://london1.linode.com/100MB-london.bin      1618.09080637961
downloading http://newark1.linode.com/100MB-newark.bin 100MB-newark.bin

两次取得的整数部分相同,但是第一次取得的没有小数部分,而第二次有。

也曾怀疑是alarm倒的鬼,去掉alarm后问题依旧。

在 2010年4月1日 下午4:43,Achilles Xu <formalin14@gmail.com>写道:
输出:

$ perl test_linode.pl
downloading http://london1.linode.com/100MB-london.bin 100MB-london.bin
1270110047      1270110047
Illegal division by zero at test_linode.pl line 30.

在 2010年4月1日 下午4:38,Achilles Xu <formalin14@gmail.com>写道:

测试代码:


use LWP::Simple qw(getstore $ua);

my @urls = (
            "http://london1.linode.com/100MB-london.bin",
            "http://newark1.linode.com/100MB-newark.bin",
            "http://atlanta1.linode.com/100MB-atlanta.bin",
            "http://dallas1.linode.com/100MB-dallas.bin",
            "http://fremont1.linode.com/100MB-fremont.bin"
);

my $timeout = 120;
$ua->default_header('Range' => 'bytes=0-1000000');
for my $url (@urls) {
  my ($file) = $url =~ m{/([^/]+)$};
  my $atime = time;
  eval {
    local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required                                                                                                        
    alarm $timeout;
    my $cmd = "wget $url";
    print "downloading $url $file\n";
    getstore($url, $file);
   
    alarm 0;
  };
  my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
                      $atime,$mtime,$ctime,$blksize,$blocks)
                          = stat($file);
  my $btime = time;
  print $btime, "\t", $atime, "\n";
  print $url, "\t" . ($size/1000/($btime - $atime)) . "\n";
  if ($@) {
    die unless $@ eq "alarm\n";   # propagate unexpected errors                                                                                                        
    # timed out                                                                                                                                                        
  }
  else {
    # didn't                                                                                                                                                           
  }
}

下载文件会需要几秒,但是几秒过去了,atime和btime是一样的,导致后面报出除0错误。

普通笔记本,联想的,intel t4400。

等会试试Time::HiRes有没有问题。

--
---------------------------
Achilles Xu




--
---------------------------
Achilles Xu




--
---------------------------
Achilles Xu

--
您收到此邮件是因为您订阅了 Google 网上论坛的"PerlChina Mongers 讨论组"论坛。
要向此网上论坛发帖,请发送电子邮件至 perlchina@googlegroups.com。
要取消订阅此网上论坛,请发送电子邮件至 perlchina+unsubscribe@googlegroups.com。
若有更多问题,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问此网上论坛。

没有评论: