|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Improve this function!
Hi, I need some help to make this function run much faster/efficiently, I currently call this function over 1000 + times while looping over data i'm pullin form the DB. It currently runs quite slow..
VB Code:
Last edited by Shadow Wizard : November 10th, 2005 at 06:25 PM. Reason: added [highlight=VB] and [/highlight] code tags around ASP code - please do that yourself next. |
|
#2
|
|||
|
|||
|
sorry,I didn't put the code inside the code tags...
Code:
Function CleanHTML(s) tmpS = s if isnull(tmpS) then tmpS= "" htmlPattern = "<([a-z/][^>]*)>" crlfPattern = "\r\n|\t" ' htmlCodePattern ="&([^#][a-z0-9]+;)" ' ampersandPattern ="&([^a-z0-9;]+)" ampersandPattern ="&" hiAsciiPattern = "\x[7F-FF]" set RegX = new RegExp RegX.Global = True RegX.IgnoreCase = True RegX.Pattern = htmlPattern tmpS = RegX.Replace(tmpS, "<$1>") tmpS = Replace(tmpS, "<", "<") tmpS = Replace(tmpS, ">", ">") ' RegX.Pattern = htmlCodePattern ' tmpS = RegX.Replace(tmpS, "&$1") RegX.Pattern = ampersandPattern tmpS = RegX.Replace(tmpS, "&") RegX.Pattern = crlfPattern tmpS = RegX.Replace(tmpS, " ") tmpS = Replace(tmpS, chr(&H92), "'") tmpS = Replace(tmpS, "'", "'") tmpS = Replace(tmpS, chr(&H93), """") tmpS = Replace(tmpS, chr(&H94), """") tmpS = Replace(tmpS, chr(&H85), "...") ' "…" tmpS = Replace(tmpS, chr(&H96), "-") ' "…" RegX.Pattern = hiAsciiPattern tmpS = RegX.Replace(tmpS, "?") CleanHTML = tmpS set RegX = nothing End Function |
|
#3
|
|||
|
|||
|
no suggestions yet
![]() perhaps i should further elaborate upon the focus of this function. I basically want to just strip all funny characters from a string of text that i will transport for use within xml. Just basic stuff that could be interpreted as markup..etc.. hope someone has an idea.. i'm not sure if the calls to replace() are costly, or the entire regex solution is the culprit for the performance hit. |
|
#4
|
|||
|
|||
|
I'd try to drastically reduce the number of times you're calling the function.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
|
#5
|
|||
|
|||
|
String processing is slow.
I think the use of tmpS = manipulated(tmpS) isn't helping, nor if it isn't declared as a variable of type string. I'd do it like this: dim strTemp as String dim tmpS as String tmpS = ... strTemp = Replace(tmpS, "<", "<") tmpS = strTemp strTemp = Replace(tmpS, ">", ">") tmpS = strTemp ...and so on |
|
#6
|
|||
|
|||
|
I simplified the code down to this..still slow..any ideas?
I figured the reg ex is slowing it down the most.. I need a way to replace all hi ascii chars quickly...any ideas? Code:
Function CleanXML(s) tmpS = s hiAsciiPattern = "\x[7F-FF]" set RegX = new RegExp RegX.Global = True RegX.IgnoreCase = True tmpS = Replace(tmpS, "&", "&") tmpS = Replace(tmpS, "<", "<") tmpS = Replace(tmpS, ">", ">") tmpS = Replace(tmpS,vbtab, " ") tmpS = Replace(tmpS,vbcrlf, " ") RegX.Pattern = hiAsciiPattern tmpS = RegX.Replace(tmpS, "?") CleanHTML = tmpS set RegX = nothing End Function |
|
#7
|
|||
|
|||
|
OK guyz, i got it to run really really fast now..
I just create the regEx object once, and pass it into the function.. now it just runs amazingly fast... something close to 5000 + calls in less then 2 seconds. w00t! i think |
|
#8
|
|||
|
|||
|
Actually that makes a lot of sense. Sorry, I didn't think of it before. Creating a variable inside a procedure does slow the procedure down, as you create it, add and modify it's value, then destroy it when you exit the procedure. For occassional use procedures, that isn't a problem, but when the procedure gets called a lot, say from a loop in another procedure, you are best to have all variables ready to go, and pass them in.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Improve this function! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|