现在的位置: 首页 > 综合 > 正文

转载:Perl与shell的性能比较

2014年04月19日 ⁄ 综合 ⁄ 共 549字 ⁄ 字号 评论关闭

原文地址:http://www.simplelife.cn/blog/post/1/718

 

分别用shell和perl逐行读一个450M的文本文件,并写入另一文件。

#!/bin/sh
while read line
do
    echo $line >> a;
done < "file4read.txt"

 

#!/usr/bin/perl
open ( readfile , "file4read.txt") or die ("Could not open the filen");
open ( writefile , ">b" );
while( $line = <readfile> )
{
    print writefile $line;
}
close( writefile );
close( readfile );

测试结果:

[root@test]# time ./read.sh 

real    13m18.797s
user    9m22.840s
sys     3m30.290s
[root@test]#
[root@test]# time ./read.pl

real    0m55.948s
user    0m10.720s
sys     0m2.980s
[root@test]#

 相当明显! 

 

抱歉!评论已关闭.