SHELL下十二种读文件的方法及运行效率

本文介绍了一种使用ksh脚本语言解析文件的12种不同方法,并比较了各种方法的执行效率。通过实际测试,展示了不同场景下最适合采用哪种读取方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

结果:

$ ./read_file.sh mylist.txt

Starting File Processing of each Method

Method 1:
function while_read_LINE
    0.58s real     0.20s user     0.48s system

Method 2:
function while_read_LINE_bottom
    0.03s real     0.00s user     0.03s system

Method 3:
function while_line_LINE_bottom
    4.41s real     0.17s user     0.40s system

Method 4:
function cat_while_LINE_line
    4.55s real     6.94s user     3.21s system

Method 5:
function while_line_LINE
    4.48s real     6.53s user     3.29s system

Method 6:
function while_LINE_line_bottom
    4.28s real     0.23s user     0.40s system

Method 7:
function while_LINE_line_cmdsub2
    4.57s real     6.73s user     3.10s system

Method 8:
function while_LINE_line_bottom_cmdsub2
    4.47s real     0.17s user     0.40s system

Method 9:
function while_read_LINE_FD
    0.02s real     0.01s user     0.01s system

Method 10:
function while_LINE_line_FD
    4.30s real     0.21s user     0.49s system

Method 11:
function while_LINE_line_cmdsub2_FD
    4.37s real     0.10s user     0.53s system

Method 12:
function while_line_LINE_FD
    4.25s real     0.10s user     0.49s system

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值