本帖最后由 tmplinshi 于 2011-7-18 11:35 编辑
我测试了一个 11651 行的文本(没有空行),结果是 for /f 更快。
测试代码:
set_p.bat:- @echo off
- (
- for /l %%a in (1 1 11651) do (
- setlocal enabledelayedexpansion
- set /p str=
- echo,!str: =_!
- endlocal
- )
- ) <test.txt >test_1.txt
复制代码 for_f.bat:- @echo off
- (
- for /f "delims=" %%a in (test.txt) do (
- set str=%%a
- setlocal enabledelayedexpansion
- echo,!str: =_!
- endlocal
- )
- ) >test_2.txt
复制代码 测试结果:
e:\我的文档\桌面>timeit set_p.bat
Version Number: Windows NT 5.1 (Build 2600)
Exit Time: 10:19 am, Monday, July 18 2011
Elapsed Time: 0:00:15.500
Process Time: 0:00:14.031
System Calls: 430474
Context Switches: 56632
Page Faults: 39304
Bytes Read: 19381026
Bytes Written: 741100
Bytes Other: 2573192
e:\我的文档\桌面>timeit for_f.bat
Version Number: Windows NT 5.1 (Build 2600)
Exit Time: 10:20 am, Monday, July 18 2011
Elapsed Time: 0:00:12.484
Process Time: 0:00:12.328
System Calls: 159911
Context Switches: 2458
Page Faults: 15433
Bytes Read: 598486
Bytes Written: 597572
Bytes Other: 2345164 |