Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 10th, 2005, 10:44 AM
omarqu omarqu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 5 omarqu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 44 sec
Reputation Power: 0
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:
Original - VB Code
  1.  
  2. Function CleanHTML(s)
  3.   tmpS = s
  4.   if isnull(tmpS) then tmpS= ""
  5.   htmlPattern       = "<([a-z/][^>]*)>"
  6.   crlfPattern       = "\r\n|\t"
  7.  
  8.   ampersandPattern  ="&"
  9.   hiAsciiPattern    = "\x[7F-FF]"
  10.  
  11.   set RegX = new RegExp
  12.   RegX.Global = True
  13.   RegX.IgnoreCase = True
  14.  
  15.   RegX.Pattern = htmlPattern
  16.   tmpS = RegX.Replace(tmpS, "<$1>")
  17.  
  18.   tmpS = Replace(tmpS, "<", "<")
  19.   tmpS = Replace(tmpS, ">", ">")
  20.  
  21.   RegX.Pattern = ampersandPattern
  22.   tmpS = RegX.Replace(tmpS, "&")
  23.  
  24.   RegX.Pattern = crlfPattern
  25.   tmpS = RegX.Replace(tmpS, " ")
  26.  
  27.   tmpS = Replace(tmpS, chr(&H92), "'")
  28.   tmpS = Replace(tmpS, "'", "'")
  29.  
  30.   tmpS = Replace(tmpS, chr(&H93), """")
  31.   tmpS = Replace(tmpS, chr(&H94), """")
  32.   tmpS = Replace(tmpS, chr(&H85), "...")
  33.   tmpS = Replace(tmpS, chr(&H96), "-")
  34.   RegX.Pattern = hiAsciiPattern
  35.   tmpS = RegX.Replace(tmpS, "?")
  36.  
  37.   CleanHTML = tmpS
  38.  
  39.   set RegX = nothing
  40. End Function

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.

Reply With Quote
  #2  
Old November 10th, 2005, 11:33 AM
omarqu omarqu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 5 omarqu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 44 sec
Reputation Power: 0
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

Reply With Quote
  #3  
Old November 10th, 2005, 02:16 PM
omarqu omarqu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 5 omarqu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 44 sec
Reputation Power: 0
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.

Reply With Quote
  #4  
Old November 10th, 2005, 07:42 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
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

Reply With Quote
  #5  
Old November 10th, 2005, 09:43 PM
q97 q97 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: Brisvegas
Posts: 276 q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 41 m 49 sec
Reputation Power: 37
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

Reply With Quote
  #6  
Old November 11th, 2005, 01:13 PM
omarqu omarqu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 5 omarqu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 44 sec
Reputation Power: 0
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

Reply With Quote
  #7  
Old November 11th, 2005, 03:14 PM
omarqu omarqu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Nov 2005
Posts: 5 omarqu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 44 sec
Reputation Power: 0
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

Reply With Quote
  #8  
Old November 13th, 2005, 08:30 PM
q97 q97 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: Brisvegas
Posts: 276 q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level)q97 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 4 Days 10 h 41 m 49 sec
Reputation Power: 37
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Improve this function!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT