转载:Perl与shell的性能比较

原文地址: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]#

 相当明显! 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值