一个疑问:用for循环超过5000次后循环会变慢,怎样解决?
一个疑问:用for循环超过5000次后循环会变慢,怎样解决? 实践证明,和你循环多少次没有关系,和你代码本身的效率有关。别说5000次了,筛选硬件ID时10万次都试过。 5000次唉~计算机累了,要休息休息再干活~估计是计算机偷懒了~楼主你要好好监督~~{:face (303):} 5000次要看干嘛了5000循环 + 1也不难....如果循环5000次装WIN8..... 偶my噶,不敢想..... 5000次变慢了,肯定是代码出问题了 回复 3# haijie1223
你别说,如果代码够拖沓,CPU过热不是不可能。。。。。 回复 5# seniors #NoTrayIcon
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#PRE_icon=..\..\..\..\..\..\Windows\syswow64\SHELL32.dll|-161
#PRE_Outfile=QQ资料性别筛选工具最后更新版.exe
#PRE_UseUpx=n
#PRE_UseX64=n
#PRE_Res_requestedExecutionLevel=None
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <Constants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include<file.au3>
#include <Array.au3>
If _Singleton(@ScriptName, 1) = 0 Then
MsgBox(64, "温馨提醒", "您只能运行一个此应用程序!")
Exit (1)
EndIf
Global $girl = 0
$Form1 = GUICreate("QQ资料性别筛选工具", 430, 320, -1, -1)
GUISetBkColor(0xCCCCFF)
$Input1 = GUICtrlCreateInput("", 10, 14, 260, 25)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
$Label2 = GUICtrlCreateLabel("性别:", 10, 85, 50, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
$Input2 = GUICtrlCreateInput("", 60, 250, 110, 25)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
$Label2 = GUICtrlCreateLabel("账号:", 10, 255, 50, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
$Input3 = GUICtrlCreateInput("", 250, 250, 150, 25)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
$Label2 = GUICtrlCreateLabel("密码:", 200, 255, 50, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
$Button1 = GUICtrlCreateButton("选择文本", 298, 13, 112, 28)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
GUICtrlSetColor(-1, 0x0000FF)
$Button2 = GUICtrlCreateButton("开始筛选", 298, 70, 112, 40)
GUICtrlSetFont(-1, 12, 400, 0, "黑体")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetState(-1, $GUI_DISABLE)
;MsgBox(0,0,GUICtrlRead($Input3))
$Combo2 = GUICtrlCreateCombo("女", 60, 80, 80, 25)
GUICtrlSetData(-1, "男")
GUICtrlSetFont(-1, 11, 0, 0, "黑体")
GUISetState()
_ReduceMemory(@AutoItPID)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Local $odialog = FileOpenDialog("选择一个文本,该文本格式为每行一个QQ", @DesktopDir & "\", "文本文件 (*.txt)", 1)
If @error Then
MsgBox(4096, "提示:", "没有选择文件!")
Else
GUICtrlSetState($Button2, $GUI_ENABLE)
GUICtrlSetData($Input1, $odialog)
EndIf
Case $Button2 ;每运行9次清理一次内存,Mod(0,9)
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetState($Button1, $GUI_DISABLE)
Local $gender = GUICtrlRead($Combo2)
Local $ahang = _FileCountLines(GUICtrlRead($Input1))
Local $QQNUM = GUICtrlRead($Input2)
Local $QQPWD = GUICtrlRead($Input3)
Local $aRecords
If Not _FileReadToArray(GUICtrlRead($Input1), $aRecords) Then
MsgBox(64, "错误提示:", "找不到导入的文本,请重新导入!" & @error)
GUICtrlSetState($Button2, $GUI_DISABLE)
GUICtrlSetState($Button1, $GUI_ENABLE)
Else
;If $times > 1 Then
;Local $Asktime=MsgBox(4,"继续上次操作","")
Run(@ScriptDir & "\Runtimes\QQ资料查询主界面.exe");运行
While 1
Sleep(200)
Local $tittle = ControlGetText("好友资料查询主界面", "", "")
If $tittle == "查询资料" Then ExitLoop
WEnd
;输入账号密码并登录和查询
ControlSetText("好友资料查询主界面", "", "", $QQNUM)
Sleep(200)
ControlSetText("好友资料查询主界面", "", "", $QQPWD)
Sleep(200)
ControlClick("好友资料查询主界面", "", "", "left", 1)
Sleep(200)
While 1
Sleep(10000)
Local $logstatus = ControlTreeView("好友资料查询主界面", "", "", "GetItemCount")
If $logstatus <> 0 Then
ExitLoop
Else
ControlSend("", "", "", "C",1)
Sleep(3000)
ControlClick("好友资料查询主界面", "", "", "left", 1)
EndIf
WEnd
$Label2 = GUICtrlCreateLabel("当前QQ: " & $ahang & "个,程序运行中,请勿关闭!", 10, 138, 300, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
GUICtrlSetColor(-1, 0x0000FF)
;GUICtrlSetState($Combo2, $GUI_DISABLE)
Dim $file = FileOpen(@ScriptDir & "\" & $gender & "-" & @MIN & @SEC & ".txt", 1)
;开始操作查询
;Local $times = IniRead(@ScriptDir & "\Runtimes\config.ini", "setup", "times", "1")
$Label22 = GUICtrlCreateLabel("", 10, 168, 300, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
GUICtrlSetColor(-1, 0xff0043)
$Label23 = GUICtrlCreateLabel("", 10, 198, 300, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
GUICtrlSetColor(-1, 0x0000FF)
For $x = 1 To $ahang
GUICtrlSetData($Label22,"正在筛选第" & $x & "个,请稍后....")
ControlSetText("好友资料查询主界面", "", "", $aRecords[$x]); 输入QQ号
Sleep(250)
ControlClick("好友资料查询主界面", "", "", "left", 1);点击查询资料
Local $cb = 1
While 1
Sleep(250)
Local $text = ControlGetText("好友资料查询主界面", "", "")
If $text <> "" Then
ExitLoop
Else
ControlClick("好友资料查询主界面", "", "", "left", 1)
$cb = $cb +1
EndIf
If $cb = 8 Then
_continue()
ControlSetText("好友资料查询主界面", "", "", $aRecords[$x]); 输入QQ号
Sleep(1000)
ControlClick("好友资料查询主界面", "", "", "left", 1);点击查询资料
EndIf
If WinExists("","如果单击") Then
_continue()
ControlSetText("好友资料查询主界面", "", "", $aRecords[$x]); 输入QQ号
Sleep(1000)
ControlClick("好友资料查询主界面", "", "", "left", 1);点击查询资料
EndIf
WEnd
If StringInStr($text, $gender & $aRecords[$x]) Then
FileWriteLine($file, $aRecords[$x])
$girl = $girl + 1
GUICtrlSetData($Label23,"已有" & $girl & "个符合条件!")
EndIf
ControlSetText("好友资料查询主界面", "", "", ""); 清空消息的文本
If Mod($x, 9) = 0 Then
Clear_Memory();9次清理一回内存
EndIf
Next
FileClose($file)
$Label2 = GUICtrlCreateLabel("", 10, 198, 300, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("", 10, 168, 300, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
GUICtrlSetColor(-1, 0xff0043)
$Label2 = GUICtrlCreateLabel("全部筛选完毕,请及时备份结果!", 10, 138, 300, 20)
GUICtrlSetFont(-1, 11, 400, 0, "黑体")
GUICtrlSetColor(-1, 0x0000FF)
EndIf
EndSwitch
WEnd
; Clear_Memory();清理内存
Func _continue()
ProcessClose("QQ资料查询主界面.exe")
ProcessClose("QQ资料查询主界面.exe")
While 1
Sleep(200)
Local $cs = ProcessExists("QQ资料查询主界面.exe")
If $cs <> 0 Then
ProcessClose("QQ资料查询主界面.exe")
ElseIf $cs = 0 Then
ExitLoop
EndIf
WEnd
;Local $Retimes = IniRead(@ScriptDir & "\Runtimes\config.ini", "setup", "times", "") + 1
Local $reQQ = GUICtrlRead($Input2)
Local $rePWD = GUICtrlRead($Input3)
Sleep(30000)
Clear_Memory()
Run(@ScriptDir & "\Runtimes\QQ资料查询主界面.exe");运行
Sleep(3000)
While 1
Sleep(200)
Local $tittle1 = ControlGetText("好友资料查询主界面", "", "")
If $tittle1 == "查询资料" Then ExitLoop
WEnd
;输入账号密码并登录和查询
ControlSetText("好友资料查询主界面", "", "", $reQQ)
Sleep(200)
ControlSetText("好友资料查询主界面", "", "", $rePWD)
Sleep(200)
ControlClick("好友资料查询主界面", "", "", "left", 1)
Sleep(200)
While 1
Sleep(10000)
Local $logstatus1 = ControlTreeView("好友资料查询主界面", "", "", "GetItemCount")
If $logstatus1 <> 0 Then
ExitLoop
Else
ControlSend("", "", "", "C",1)
Sleep(3000)
ControlClick("好友资料查询主界面", "", "", "left", 1)
EndIf
WEnd
EndFunc ;==>_continue
Func Clear_Memory()
Local $i, $mem = MemGetStats()
Local $MemGet1 = $mem
Local $ProcessList = ProcessList()
For $i = 1 To $ProcessList
_ReduceMemory($ProcessList[$i])
Next
$mem = MemGetStats()
Local $MemGet2 = $mem
Local $Memory = ($MemGet2 - $MemGet1) / 1024
EndFunc ;==>Clear_Memory
Func _ReduceMemory($i_PID = @AutoItPID)
If $i_PID <> -1 Then
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle)
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle)
Else
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return
EndFunc ;==>_ReduceMemory
附上源码如上,前2000次基本每秒一次,越往后就有点慢。好友资料查询主界面这个程序就不提供,因为这个程序不是au3写的,经常出错,If WinExists("","如果单击") 这一句就是判断出错的,_continue()用来重启好友资料查询主界面这个程序。 电脑也是泪了 {:face (303):} 你代码问题,不关for的事 好吧,你先算下你那一次要走多少判断和延迟,还一次就9遍,放不放内存都没用了 代码写的效率不好吧
页:
[1]