[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] mawk: 最快的 awk(快于 C, C++, Java, Perl, Ruby,...)

mawk 在处理体积较大的文本时,速度快于大部分语言。(当然,有可能其他语言写的不是最佳代码。)

以下两个链接有速度对比:


我测试了一个 4MB 的文本,测试结果为:

  • gawk 耗时 8.375 秒;
  • awka 转成 c 源码编译出来的 exe,耗时 3.046 秒;
  • mawk 耗时 2.703 秒。


E:\我的文档\桌面\awka\新建文件夹>timeit gawk.exe -f test.awk test.txt >nul

Version Number:   Windows NT 5.1 (Build 2600)
Exit Time:        10:00 am, Monday, May 20 2013
Elapsed Time:     0:00:08.375
Process Time:     0:00:08.390
System Calls:     201908
Context Switches: 98745
Page Faults:      6790
Bytes Read:       4611650
Bytes Written:    327340
Bytes Other:      650953

E:\我的文档\桌面\awka\新建文件夹>timeit test.exe test.txt >nul

Version Number:   Windows NT 5.1 (Build 2600)
Exit Time:        10:00 am, Monday, May 20 2013
Elapsed Time:     0:00:03.046
Process Time:     0:00:03.046
System Calls:     97107
Context Switches: 36341
Page Faults:      28548
Bytes Read:       4450691
Bytes Written:    109665
Bytes Other:      327492

E:\我的文档\桌面\awka\新建文件夹>timeit mawk.exe -f test.awk test.txt >nul

Version Number:   Windows NT 5.1 (Build 2600)
Exit Time:        10:01 am, Monday, May 20 2013
Elapsed Time:     0:00:02.703
Process Time:     0:00:02.718
System Calls:     66853
Context Switches: 32698
Page Faults:      3051
Bytes Read:       4454663
Bytes Written:    110994
Bytes Other:      326450


------------------------------------------------------------

e:\我的文档\桌面>mawk
mawk: no program

mawk: SYNOPSIS
   mawk [-W option] [-F value] [-v var=value] [--] 'program text' [file ...]
   mawk [-W option] [-F value] [-v var=value] [-f program-file] [--] [file ...]

mawk: OPTIONS
-W version     -Wv      Version info;
-W dump        -Wd      outputs assembler-like internal code representation;
-W interactive -Wi      unbuff. writes => stdout, line buff. reads <= stdin;
-W exec file   -We file last option: Program is read from file;
-W sprintf=num -Ws=num  set size of the internal sprintf buffer to num bytes;
-W posix_space -Wp      forces mawk not to consider '\n' to be space;
-F value                sets the field separator, FS, to value;
-v var=value            assigns value to program variable var;
-f program-file         program text is read from file instead of from the
                         command line, multiple use of -f options is allowed;
--                      indicates the unambiguous end of options.


e:\我的文档\桌面>mawk -W version
mawk 1.3.3/Win32 Nov 1996, Copyright (C) Michael D. Brennan

Ported to Win32 by O. Schoenfeldt (http://www.klabaster.com)

Open Watcom C/C++ 1.8

compiled limits:
max NF             32767
sprintf buffer      1020


-----------------------------------------
http://www.klabaster.com/freeware.htm#mawk
-----------------------------------------

http://bcn.bathome.net/s/tool/index.html?key=mawk

还不会怎么用呢 学习一下

TOP

如果真能快过C语言,那就太神奇了,难道是汇编?

TOP

代码比较优化嘛,是不是

TOP

不过这个速度"最快"的荣誉属于1.3.3版,到了1.3.4版就大幅降下来了
用楼主所给的数据居然需要处理约15s,几乎是gawk 3.1.5版的两倍
用gawk 4.1测试,约11s
也就是说,版本的不同,也会有速度上的差异,需要选好版本
另外,mawk一个比较要命的问题是:正则表达式不支持{m,n}这样的区间
1

评分人数

尺有所短寸有所长,学好批处理没商量;
考虑问题复杂化,解决问题简洁化。

心在天山,身老沧州。

TOP

回复 5# namejm


    mawk --re-interval 支持这个参数吗?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

在 mawk 中写上 --re-interval 时也没法支持正则的 {m,n} 区间表达
尺有所短寸有所长,学好批处理没商量;
考虑问题复杂化,解决问题简洁化。

心在天山,身老沧州。

TOP

返回列表