标题:
[转帖]行方式读与数组方式读之比较
[打印本页]
作者:
cnangel
时间:
2003-8-10 15:26
标题:
[转帖]行方式读与数组方式读之比较
先看看这个再看看下面的:
http://com2008.51.net/cgi-bin/bbs/cgi-bin/topic.cgi?forum=23&topic=25&show=0
测试数据:list.cgi,大约8000行,文件大小:500KB
测试程序1是采用了行方式读,而测试程序2是采用了数组方式读。
测试程序1:test1.cgi
#!/usr/bin/perl
use CGI;
use Benchmark;
$TT0 = new Benchmark;
print "Content-type: text/html\n\n";
$/="";
open (FILES, "list.cgi");
$reads=<FILES>;
close(FILES);
$/="\n";
@reads=split ( /\n/,$reads);
foreach (@reads){
print $_;
}
###########################
print"<hr>";
$TT1 = new Benchmark;
$td = Benchmark::timediff($TT1, $TT0);
$td = Benchmark::timestr($td);
$td =~ /(\d+)\s*wallclock secs \(\s*?(\d*?\.\d*?)\s*usr\s*\+\s*(\d*?\.\d*?)\s*sys/i;
my $alltimas=($2+$3)*1000;
print "<center><font color=$cpudispcolor>程序占用 CPU 时间:$2 usr + $3 sys 合计运行时间 $alltimas 毫秒";
exit;
测试程序2:
#!/usr/bin/perl
use CGI;
use Benchmark;
$TT0 = new Benchmark;
print "Content-type: text/html\n\n";
open (FILES, "list.cgi");
@reads=<FILES>;
close(FILES);
foreach (@reads){
print $_;
}
###########################
print"<hr>";
$TT1 = new Benchmark;
$td = Benchmark::timediff($TT1, $TT0);
$td = Benchmark::timestr($td);
$td =~ /(\d+)\s*wallclock secs \(\s*?(\d*?\.\d*?)\s*usr\s*\+\s*(\d*?\.\d*?)\s*sys/i;
my $alltimas=($2+$3)*1000;
print "<center><font color=$cpudispcolor>程序占用 CPU 时间:$2 usr + $3 sys 合计运行时间 $alltimas 毫秒";
exit;
欢迎光临 星星博客 (http://commerce.huhoo.net/)
Powered by Discuz! 7.0.0