本帖最后由 3mile 于 2011-3-14 13:15 编辑
借用水木子的思路 我用了0.006毫秒
shenrenba 发表于 2011-3-14 11:50
首先你的时间统计是有问题的.你的时间统计只是MSGBOX的反应时间.
如下面的代码再测试:
$sText = "key=白骨精他妈" & @CRLF & _
"key=沙和尚" & @CRLF & _
"key=白骨" & @CRLF & _
"key=孙悟空" & @CRLF & _
"key=沙和尚" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨精" & @CRLF & _
"key=白骨" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨精" & @CRLF & _
"key=白骨精他妈" & @CRLF & _
"key=孙悟空"&@CRLF
$time=TimerInit()
$reulst= jj($sText)
MsgBox(0,Round(TimerDiff($time),5)&"毫秒", $reulst)
Func jj($Text)
$sRer = StringRegExpReplace($Text, "(?m)(key=.+)(?=[^\1]+\1$)", "")
$sRer = StringRegExpReplace($sRer, '^\v+|\r?\n(?=\r?\n)|\r?\n$', '')
$sr = StringRegExp($sRer, "(key=.+)(?=[^\1]+\1\v)", 3)
If Not @error Then
jj($sRer)
Else
Return $sRer
EndIf
EndFunc
其次你的效率也是有问题的.下面的代码测试:
$sText = "key=白骨精他妈" & @CRLF & _
"key=沙和尚" & @CRLF & _
"key=白骨" & @CRLF & _
"key=孙悟空" & @CRLF & _
"key=沙和尚" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨精" & @CRLF & _
"key=白骨" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨精" & @CRLF & _
"key=白骨精他妈" & @CRLF & _
"key=孙悟空"&@CRLF
$hfile=FileOpen("test.txt",1)
FOR $I=1 TO 3000
FileWrite($hfile,$sText)
ToolTip($i)
Next
FileClose($hfile)
$sText=fileread("test.txt")
$time=TimerInit()
$reulst= jj($sText)
MsgBox(0,Round(TimerDiff($time),5)&"毫秒", $reulst)
Func jj($Text)
$sRer = StringRegExpReplace($Text, "(?m)(key=.+)(?=[^\1]+\1$)", "")
$sRer = StringRegExpReplace($sRer, '^\v+|\r?\n(?=\r?\n)|\r?\n$', '')
$sr = StringRegExp($sRer, "(key=.+)(?=[^\1]+\1\v)", 3)
If Not @error Then
jj($sRer)
Else
Return $sRer
EndIf
EndFunc
用我的代码再来测试:
#include <File.au3>
$sText = "key=白骨精他妈" & @CRLF & _
"key=沙和尚" & @CRLF & _
"key=白骨" & @CRLF & _
"key=孙悟空" & @CRLF & _
"key=沙和尚" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨精" & @CRLF & _
"key=白骨" & @CRLF & _
"key=白骨夫人" & @CRLF & _
"key=白骨精" & @CRLF & _
"key=白骨精他妈" & @CRLF & _
"key=孙悟空"&@CRLF
$hfile=FileOpen("test.txt",1)
FOR $I=1 TO 3000
FileWrite($hfile,$sText)
ToolTip($i)
Next
FileClose($hfile)
$sText=fileread("test.txt")
;~ $aFile = FileOpenDialog("快速删除重复行",@ScriptDir&"\","文本文件 (*.txt)", 1 + 4)
;~ If @error Then
;~ MsgBox(0,0,"文件未选择",3)
;~ Exit
;~ EndIf
$aFile=@ScriptDir&"\test.txt"
$begin = TimerInit()
Local $str='',$file_array
_FileReadToArray($aFile,$file_array)
;_ArrayDisplay($file_array)
For $i = 1 To UBound($file_array)-1
$temp=$file_array[$i]
If Not IsDeclared($temp) Then
Assign($temp, $i)
$str&=$temp&@CRLF
EndIf
Next
$dif = TimerDiff($begin)
$out_file=StringTrimRight($aFile,4)&'_已完成.txt'
if FileExists($out_file) then FileDelete($out_file)
FileWrite($out_file,$str)
ShellExecute($out_file)
WinWaitActive("[CLASS:Notepad]")
WinSetTitle("[CLASS:Notepad]", "", '处理'&UBound($file_array)&'行'&' 用时'&int($dif)&'毫秒')
Exit
|