Performance Question
-
Can someone please look at this and make some suggestions on how to improve the performance of this snippet this is killing one of our apps. Private Function fbParseParameters(ByVal sArgs() As String) As Boolean Dim tTemp As String ' fbParseParameters = True Dim iII As Integer = 0 If sArgs.Length > 0 Then ' each parameter is broken into a seperate array item. While iII < sArgs.Length tTemp = sArgs(iII).ToUpper ' look at the parms, and figure out which is which... If tTemp.IndexOf("DATABASEHOST=") > 0 Then myConnectionInfo.tDatabaseHost = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("USERNAME=") > 0 Then myConnectionInfo.tUserName = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("USERNUMBER=") > 0 Then myConnectionInfo.lUserNumber = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("PASSWORD=") > 0 Then myConnectionInfo.tPassword = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("LOCALE=") > 0 Then myConnectionInfo.tCurrentLocaleCode = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("LOCALEDESCR=") > 0 Then myConnectionInfo.tCurrentLocale = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("MODULE=") > 0 Then strApplicationInfo.tCurrentModule = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("REPORT=") > 0 Then strApplicationInfo.tReport = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If
-
Can someone please look at this and make some suggestions on how to improve the performance of this snippet this is killing one of our apps. Private Function fbParseParameters(ByVal sArgs() As String) As Boolean Dim tTemp As String ' fbParseParameters = True Dim iII As Integer = 0 If sArgs.Length > 0 Then ' each parameter is broken into a seperate array item. While iII < sArgs.Length tTemp = sArgs(iII).ToUpper ' look at the parms, and figure out which is which... If tTemp.IndexOf("DATABASEHOST=") > 0 Then myConnectionInfo.tDatabaseHost = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("USERNAME=") > 0 Then myConnectionInfo.tUserName = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("USERNUMBER=") > 0 Then myConnectionInfo.lUserNumber = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("PASSWORD=") > 0 Then myConnectionInfo.tPassword = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("LOCALE=") > 0 Then myConnectionInfo.tCurrentLocaleCode = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("LOCALEDESCR=") > 0 Then myConnectionInfo.tCurrentLocale = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("MODULE=") > 0 Then strApplicationInfo.tCurrentModule = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("REPORT=") > 0 Then strApplicationInfo.tReport = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If
You're using tTemp.Substring(tTemp.IndexOf("=") + 1 multiple times in each block. If you defined your search strings as constants, you could skip this. For example: private const DATABASEHOST_ARG As String = "DATABASEHOST=" ... If tTemp.IndexOf(DATABASEHOST_ARG) > 0 Then myConnectionInfo.tDatabaseHost = tTemp.Substring(DATABASEHOST_ARG.Length(), _ (tTemp.Length - DATABASEHOST_ARG.Length()) End If I didn't compile, so formatting may be off - and make sure you check to see that I've got the Substring starting index correct. I'm pretty sure that the '+ 1' is no longer necessary. Simply rinse and repeat for your other blocks and your helpful compiler should replace a lot of "IndexOf" operations with simple math!
-
You're using tTemp.Substring(tTemp.IndexOf("=") + 1 multiple times in each block. If you defined your search strings as constants, you could skip this. For example: private const DATABASEHOST_ARG As String = "DATABASEHOST=" ... If tTemp.IndexOf(DATABASEHOST_ARG) > 0 Then myConnectionInfo.tDatabaseHost = tTemp.Substring(DATABASEHOST_ARG.Length(), _ (tTemp.Length - DATABASEHOST_ARG.Length()) End If I didn't compile, so formatting may be off - and make sure you check to see that I've got the Substring starting index correct. I'm pretty sure that the '+ 1' is no longer necessary. Simply rinse and repeat for your other blocks and your helpful compiler should replace a lot of "IndexOf" operations with simple math!
Thank you I will add that with some other things that I have done to it and that should help.
Humble Programmer
-
Can someone please look at this and make some suggestions on how to improve the performance of this snippet this is killing one of our apps. Private Function fbParseParameters(ByVal sArgs() As String) As Boolean Dim tTemp As String ' fbParseParameters = True Dim iII As Integer = 0 If sArgs.Length > 0 Then ' each parameter is broken into a seperate array item. While iII < sArgs.Length tTemp = sArgs(iII).ToUpper ' look at the parms, and figure out which is which... If tTemp.IndexOf("DATABASEHOST=") > 0 Then myConnectionInfo.tDatabaseHost = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("USERNAME=") > 0 Then myConnectionInfo.tUserName = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("USERNUMBER=") > 0 Then myConnectionInfo.lUserNumber = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("PASSWORD=") > 0 Then myConnectionInfo.tPassword = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("LOCALE=") > 0 Then myConnectionInfo.tCurrentLocaleCode = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("LOCALEDESCR=") > 0 Then myConnectionInfo.tCurrentLocale = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("MODULE=") > 0 Then strApplicationInfo.tCurrentModule = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If If tTemp.IndexOf("REPORT=") > 0 Then strApplicationInfo.tReport = tTemp.Substring(tTemp.IndexOf("=") + 1, _ (tTemp.Length - (tTemp.IndexOf("=") + 1))) End If
Split the string with delimiter "/" into string array, then from there split with delimiter "=" then put the pair into HashTable. Then assign your class from the HashTable (check for empty), ie strSystemInfo.lTherapistNum = hashTable["THERAPISTNUM"].Value;