Author Topic: INI file subroutine taking long time to run  (Read 426 times)

erezpaz

  • Jr. Member
  • **
  • Posts: 55
INI file subroutine taking long time to run
« on: January 30, 2018, 05:55:20 am »
Hi

I got a subroutine that getting two, two dimension arrays and compare them and write a list of elements in INI file. It looks for specific element in each and if it is the same it write the data. Since I use 4 for command nested it takes long time to complete on array with more them 10 elements. It can take 5,10 even 15 minutes. Can someone look at the code and give his feedback?

Thanks

Code: [Select]
#DEFINESUBROUTINE WrtieInIJobList()
if tooldebugWBERROR == 0 then IntControl(73,3,0,"OnNextError",0)
WriteLog(LogFile,"Writing list of servers to JOB file",cPC,tool,EVNTerror,TMPdir,1)
IniDeletePvt("JobList", @WHOLESECTION,INIFile)
delay(2)
CheckBusyFile(INIFile)
aJobListfromINIstr = fileopen(INIFile,"APPEND",@FALSE,TimeRetryFileOpen)
filewrite(aJobListfromINIstr,"[JobList]")
ff=""
nRmax1 = ArrInfo(JobListFromGui,1)
nCmax1 = ArrInfo(JobListFromGui,2)
nRmax2 = ArrInfo(JobListfromINIArr,1) ; REPLACE with array from advanced menu
nCmax2 = ArrInfo(JobListfromINIArr,2)
for i = 0 to nRmax1-1 ;GUI
ggg=0
GUIDGUI = JobListFromGui[i,10]
RecoveryPlan = JobListFromGui[i,0]
for j = 0 to nCmax1-1
for a = 0 to nRmax2-1   ;INI
for b = 0 to nCmax2-1
if DRprodMaster == 4 | DRprodMaster == 5 | DRprodMaster == 6  then
if strindex(JobListfromINIArr[a,0],"_*_",1,@FWDSCAN) == 0 then
FirstParamArry = strcat(JobListfromINIArr[a,0],"_*_",RecoveryPlan)
else
FirstParamArry = JobListfromINIArr[a,0]
end if
else
FirstParamArry = JobListfromINIArr[a,0]
end if
strForiniNew = strcat(FirstParamArry,";",JobListfromINIArr[a,1],";",JobListfromINIArr[a,2],";",JobListfromINIArr[a,3],";",JobListfromINIArr[a,4],";",JobListfromINIArr[a,5],";",JobListfromINIArr[a,6],";",JobListfromINIArr[a,7],";",JobListfromINIArr[a,8],";",JobListfromINIArr[a,9],";",JobListfromINIArr[a,10])
strForiniNew = strcat(strForiniNew,";",JobListfromINIArr[a,11],";",JobListfromINIArr[a,12],";",JobListfromINIArr[a,13],";",JobListfromINIArr[a,14],";",JobListfromINIArr[a,15],";",JobListfromINIArr[a,16],";",JobListfromINIArr[a,17],";",JobListfromINIArr[a,18],";",JobListfromINIArr[a,19],";",JobListfromINIArr[a,20],";",JobListfromINIArr[a,21],";",JobListfromINIArr[a,22])
GUIDINI = JobListfromINIArr[a,0]
if DRprodMaster == 4 | DRprodMaster == 5 | DRprodMaster == 6 then
if strindex(JobListfromINIArr[a,0],"_*_",1,@FWDSCAN) <> 0 then GUIDINI = strsub(JobListfromINIArr[a,0],1,strscan(JobListfromINIArr[a,0],"_*_",1,@FWDSCAN)-1)
end if
next
if GUIDINI == GUIDGUI & ggg == 0 then
filewrite(aJobListfromINIstr,strForiniNew)
ggg=1
end if
next
next
if ggg == 0 then
if GUIDGUI <> 0 then
if DRprodMaster == 4 | DRprodMaster == 5 | DRprodMaster == 6 then
GUIDGUI = strcat(GUIDGUI,"_*_",RecoveryPlan,";;;;;;;;;;;;;;;;;;;;;")
else
GUIDGUI = strcat(GUIDGUI,";;;;;;;;;;;;;;;;;;;;;")
end if
filewrite(aJobListfromINIstr,GUIDGUI)
end if
end if
next
fileclose(aJobListfromINIstr)
WriteLog(LogFile,"Finished writing list of servers to JOB file",cPC,tool,EVNTerror,TMPdir,1)
return
#ENDSUBROUTINE

td

  • Tech Support
  • *****
  • Posts: 2440
    • WinBatch
Re: INI file subroutine taking long time to run
« Reply #1 on: January 30, 2018, 07:40:43 am »
You have created close to an O(n4) solution.  It is going to be slow.  Without knowing your data sources it is difficult to suggest an alternative but you might consider a sort and search approach to the problem.   It may or may not be a more efficient solution.   
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


td

  • Tech Support
  • *****
  • Posts: 2440
    • WinBatch
Re: INI file subroutine taking long time to run
« Reply #2 on: January 30, 2018, 05:50:51 pm »
Should mention that the ArraySort and ArraySearch functions can be, as the names suggest, used for sorting and searching arrays.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


erezpaz

  • Jr. Member
  • **
  • Posts: 55
Re: INI file subroutine taking long time to run
« Reply #3 on: January 31, 2018, 05:11:57 am »
I changed it to use ArraySearch and it improve the time from 5 min to 5 sec !!