Login | |
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/28/2008 8:02:31 AM
|
|
 |
|
| |
dm_4ever
Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Just a little something to add... You don't necessarily need a RegExp for the date...the following would work strMonth = Right("00" & Month(strYesterday), 2) strDay = Right("00" & Day(strYesterday), 2) strYear = Year(strYesterday) If you're going to read the entire content...you don't need to use the Do Until.... used below. Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readall arrLogEntries = Split(strNextLine , vbcrlf) Loop ...you could simply do........ arrLogEntries = Split(objTextFile.ReadAll, vbCrLf) However, since your intent is to go through each line...then why bother adding it to an array...why not Do Until objTextFile.AtEndOfStream strLine = objTextFile.ReadLine strPattern = strYear & "-" & strMonth & "-" & strDay objRegEx.Pattern = strPattern If objRegEx.Test(strLine) Then objRegEx.Pattern = "(RESULT=""Success"")" If objRegEx.Test(strLine) Then objRegEx.Pattern = "(\\\\[\w-]+\\[^\\/:*?<>|""]+)((?:\\[^\\/:*?<>|""]+)*\\?)" If objRegEx.Test(strLine) Call LogToFile(objRegEx.Execute(strLine).SubMatches(0), "Migrations_" & strYear & strMonth & strDay & ".txt") strMigratedFileCount = strMigratedFileCount + 1 Else Call LogToFile("An error has occurred matching the UNC path of this log entry, it " & _ "seems to be a directory, not a file. " & VbCrLf & "Log Entry: " & strLine, "ReportErrors_" & strYear & strMonth & strDay & ".txt") End If End If End If Loop objTextFile.Close ....oh and you don't have to say objRegEx.Test(xxx) = True since this is a bit redundant
< Message edited by dm_4ever -- 6/28/2008 8:03:45 AM >
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/28/2008 4:39:48 PM
|
|
 |
|
| |
dm_4ever
Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
I tend to break just about everything I do into a sub or function and try to stay away from global variables as much as possible....if a sub/functions will be called several times and it creates a particular object several times...say like WScript.Shell or Scripting.FileSystem then I will normally create it once and pass it to any other sub or function (that's my personal prefrence and I don't recall what I did, but it did make a slight difference; though in most cases having it be self contained might be worth sacrificing a few seconds) One other thing you may consider with parsing such large files is seeing if you can find a RegEx pattern that will match exactly what you're looking for in one shot. Set colMatches = objRegEx.Execute(objTextFile.ReadAll) For Each objMatch in colMatches ...code that deals with each match Next
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/29/2008 12:52:31 AM
|
|
 |
|
| |
DiGiTAL.SkReAM
Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
|
dm_4ever: >...you could simply do........ > >arrLogEntries = Split(objTextFile.ReadAll, vbCrLf) > >However, since your intent is to go through each line...then why bother adding it to an array...why not http://www.visualbasicscript.com/fb.aspx?m=47020 shows some examples of performance issues with reading large files. At the filesizes the OP is using, it might be faster to read the entire file than to process it in a line-by-line fashion. Also I suspect that a large amount of the processing 'overhead' is having to do with the RegEx usage. When comparing InStr() vs. RegEx, InStr() will win every time - as long as it is a case sensitive search. RegEx is useful/nice when using it against a few things, but when using it against a file that might have thousands upon thousands of lines.... it becomes quite the anchor around your feet.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers) "It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
|
|
| |
|
|
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/29/2008 2:09:51 AM
|
|
 |
|
| |
yfki
Posts: 73
Score: 0
Joined: 12/12/2007
Status: offline
|
So revamped the script, removed 4 subs, and combined a bunch of other stuff. Before I was getting the files for pasring, then parsing the files entries for the UNC path, writing to a file, then reading the file into an array, and retrieving the size of each file. and finally writing that to a new file etc....(This approach was originally done, in fear of memory issues, did'nt want to load that much stuff) There was way to much overhead. With removing the extra subs, and updating the Parse() sub to handle alot more in the For Each loop, I dont have to load everything into memeory anymore. Including DM's reccomendations, speed has improoved dramatically! Look at the memory consumption as well. Some results: Before: -------------------------- HSM Migration Report 6/29/2008 2:22:58 AM -------------------------- Total Files: 87896 Total Size: 521 GB 533,743 MB Run Time: 68 minutes Working Set Size Peak: 368,557 K After: -------------------------- HSM Migration Report 6/29/2008 5:22:58 AM -------------------------- Total Files: 87896 Total Size: 521 GB 533,743 MB Run Time: 21 minutes Working Set Size Peak: 4096 K
|
|
| |
|
|
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/29/2008 4:42:00 AM
|
|
 |
|
| |
dm_4ever
Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
InStr() is faster, but it also has its limitations...especially if you intend on extracting specific pieces of information or are looking for patterns rather than specific values. If anything I think using the InStr() function to check for the date and the "Result = "Success"" would provide some additional speed improvements...but the RegExp would still be my choice to extract the path...it's simply easier than having to do InStr() with Mid/Left/Right functions to extract that info. This has been discussed several times and I think it really depends on what you ultimate goal is...it sometimes makes a difference. http://www.visualbasicscript.com/m_44624/tm.htm http://www.visualbasicscript.com/m_43401/tm.htm
< Message edited by dm_4ever -- 6/29/2008 4:46:39 AM >
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/29/2008 5:30:41 AM
|
|
 |
|
| |
TNO
Posts: 1066
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
|
Could you post your new sub? After the obvious optimizations are done, some not so obvious ones (Like loop unrolling) may help
_____________________________
To iterate is human, to recurse divine. -- L. Peter Deutsch
|
|
| |
|
|
|
 |
RE: How to make Sub faster/more efficient? --Takes to long - 6/29/2008 6:49:14 AM
|
|
 |
|
| |
dm_4ever
Posts: 2433
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
In the first sub you may be able to combine the last to For Each... into one i.e. For Each objFile In colFiles If InStr(LCase(objFile.Name), "migrate") > 0 Then strDateDifference = DateDiff("h", objFile.DateLastModified, Now) If strDateDifference < 48 Then objFile.Copy strTempDir & objFile.Name, True End If End If Next
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
|
|