Fastest way to perform 300 match-replace statements 
Author Message
 Fastest way to perform 300 match-replace statements

Here's the scenario:

I've got 40 or so passages of text coming from the database and being
displayed on a page.

I've got 300 patterns of characters which - if present in the text - are to
be replaced with small images.

The patterns come from the database.

Currently I split the passages - one at a time - into words split by spaces.
I match each word against an application variable containing
pattern/replaceWith combinations. It works surprisingly well and is quicker
than I thought it should be.

I'd like to improve it, however.

I'd like to match the 300 patterns - one at a time, in a loop - against all
40 passages in one hit. I'm thinking of retrieving these from the database
as a GetString, perform 300 loops for the replace command (once per
pattern), split the GetString into an array and then response.write them to
the page with whatever html around them.

Question:

Is this a sound idea? Is the speed on 300 replace commands in a loop
noticeable?

Should I be considering a c .dll or script component?

Would a regular expression (performed 300 times) e quicker or slower? The
patterns are fixed and not complicated, ie a regular replace will suffice.
But what about speed?

Opinions? Better solutions to look into?



Thu, 09 Sep 2004 11:57:38 GMT  
 Fastest way to perform 300 match-replace statements

Quote:
> I've got 300 patterns of characters which - if present in the text - are
to
> be replaced with small images.

I'm wondering whether the characters' names are like the images' names.
e.g.,

I am a <b>boy</b>. You're a <b>girl</b>.

And there are /boy.gif/ and /girl.gif/. In this case replacing will be easy
without loop. I'm not sure whether I'm understanding your question exactly.

In another case, are the images are saved as a blob in database? In this
case the loop looks inevitable. However I'm not sure of your condition.



Fri, 10 Sep 2004 09:49:59 GMT  
 Fastest way to perform 300 match-replace statements
Replacing with images ... yes ... there are a couple of hundred images and a
couple of hundred corresponding patterns. So, search for pattern1 and
replace with <img src="whatever.gif"> etc.

The list is coming from a database, so it's going to be an array (getrows)
from a recordset.

Now, what's the quickest way? Iw as just going to loop through the array of
pattern/replace with pairs ...


Quote:
> > I've got 300 patterns of characters which - if present in the text - are
> to
> > be replaced with small images.

> I'm wondering whether the characters' names are like the images' names.
> e.g.,

> I am a <b>boy</b>. You're a <b>girl</b>.

> And there are /boy.gif/ and /girl.gif/. In this case replacing will be
easy
> without loop. I'm not sure whether I'm understanding your question
exactly.

> In another case, are the images are saved as a blob in database? In this
> case the loop looks inevitable. However I'm not sure of your condition.



Fri, 10 Sep 2004 09:55:43 GMT  
 Fastest way to perform 300 match-replace statements
At this time temporarily, looks,
If you can do without /getrows/, it'll be faster.
If you can make the file names look like the /pattern/ string, it'll be
faster.
However temporary conclusion. Can you show us one or two /passages/ in the
database, and your code also?
--
Han
Seoul, Korea


Quote:
> Replacing with images ... yes ... there are a couple of hundred images and
a
> couple of hundred corresponding patterns. So, search for pattern1 and
> replace with <img src="whatever.gif"> etc.

> The list is coming from a database, so it's going to be an array (getrows)
> from a recordset.

> Now, what's the quickest way? Iw as just going to loop through the array
of
> pattern/replace with pairs ...



> > > I've got 300 patterns of characters which - if present in the text -
are
> > to
> > > be replaced with small images.

> > I'm wondering whether the characters' names are like the images' names.
> > e.g.,

> > I am a <b>boy</b>. You're a <b>girl</b>.

> > And there are /boy.gif/ and /girl.gif/. In this case replacing will be
> easy
> > without loop. I'm not sure whether I'm understanding your question
> exactly.

> > In another case, are the images are saved as a blob in database? In this
> > case the loop looks inevitable. However I'm not sure of your condition.



Fri, 10 Sep 2004 11:09:37 GMT  
 Fastest way to perform 300 match-replace statements
I haven't written the code for it yet, hence I can't post anything.

I was going to use GetRows because I have read in a gazillion areas that it
is faster for looping purposes than using a recordset.

Something like (really rudimentary, but an example)

Const cThePattern = 0
Const cTheReplace = 1

arMatch = rs.GetRows

For intCount = 0 To UBound(arMatch, 2)

    Replace(theText, arMatch(cThePattern, intCount), arMatch(cTheReplace,
intCount) )

Next

How fast would this be for 250 iterations on a string about 10,000
characters in length?


Quote:
> At this time temporarily, looks,
> If you can do without /getrows/, it'll be faster.
> If you can make the file names look like the /pattern/ string, it'll be
> faster.
> However temporary conclusion. Can you show us one or two /passages/ in the
> database, and your code also?
> --
> Han
> Seoul, Korea



> > Replacing with images ... yes ... there are a couple of hundred images
and
> a
> > couple of hundred corresponding patterns. So, search for pattern1 and
> > replace with <img src="whatever.gif"> etc.

> > The list is coming from a database, so it's going to be an array
(getrows)
> > from a recordset.

> > Now, what's the quickest way? Iw as just going to loop through the array
> of
> > pattern/replace with pairs ...



> > > > I've got 300 patterns of characters which - if present in the text -
> are
> > > to
> > > > be replaced with small images.

> > > I'm wondering whether the characters' names are like the images'
names.
> > > e.g.,

> > > I am a <b>boy</b>. You're a <b>girl</b>.

> > > And there are /boy.gif/ and /girl.gif/. In this case replacing will be
> > easy
> > > without loop. I'm not sure whether I'm understanding your question
> > exactly.

> > > In another case, are the images are saved as a blob in database? In
this
> > > case the loop looks inevitable. However I'm not sure of your
condition.



Sat, 11 Sep 2004 02:19:08 GMT  
 Fastest way to perform 300 match-replace statements
Hi JAM.

If you simply replace certain pattern string to a field value,

select left([a],instr([a],"$")-1)+[b]+mid([a],instr([a],"$")+1) from table1

I guess this kind of SQL can do. Can you show us one or more /passage/ and
its counterpart field?

--
Han
Seoul, Korea


Quote:
> I haven't written the code for it yet, hence I can't post anything.

> I was going to use GetRows because I have read in a gazillion areas that
it
> is faster for looping purposes than using a recordset.

> Something like (really rudimentary, but an example)

> Const cThePattern = 0
> Const cTheReplace = 1

> arMatch = rs.GetRows

> For intCount = 0 To UBound(arMatch, 2)

>     Replace(theText, arMatch(cThePattern, intCount), arMatch(cTheReplace,
> intCount) )

> Next

> How fast would this be for 250 iterations on a string about 10,000
> characters in length?



> > At this time temporarily, looks,
> > If you can do without /getrows/, it'll be faster.
> > If you can make the file names look like the /pattern/ string, it'll be
> > faster.
> > However temporary conclusion. Can you show us one or two /passages/ in
the
> > database, and your code also?
> > --
> > Han
> > Seoul, Korea



> > > Replacing with images ... yes ... there are a couple of hundred images
> and
> > a
> > > couple of hundred corresponding patterns. So, search for pattern1 and
> > > replace with <img src="whatever.gif"> etc.

> > > The list is coming from a database, so it's going to be an array
> (getrows)
> > > from a recordset.

> > > Now, what's the quickest way? Iw as just going to loop through the
array
> > of
> > > pattern/replace with pairs ...



> > > > > I've got 300 patterns of characters which - if present in the
text -
> > are
> > > > to
> > > > > be replaced with small images.

> > > > I'm wondering whether the characters' names are like the images'
> names.
> > > > e.g.,

> > > > I am a <b>boy</b>. You're a <b>girl</b>.

> > > > And there are /boy.gif/ and /girl.gif/. In this case replacing will
be
> > > easy
> > > > without loop. I'm not sure whether I'm understanding your question
> > > exactly.

> > > > In another case, are the images are saved as a blob in database? In
> this
> > > > case the loop looks inevitable. However I'm not sure of your
> condition.



Sat, 11 Sep 2004 08:24:04 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Reg: Using Vb code how to perform some functions in Epson LQ-300 printer

2. Microsoft Press More Than 300 Titles + FREE UPS Ground shipping

3. How to perform special replace in word

4. Information on HPBASIC for the HP9000/300 (MC68010)

5. TIFF for Visual Voice - 300.tif (1/1)

6. TIFF for Visual Voice - 300.tif (0/1)

7. HP 9000 Series 300 BASIC refs need

8. Crystal reports select expert can only read first 300 records from sybase

9. Text String via MODEM at 300 baud

10. ASCII-Files over 300 MB

11. decompiling vb3...error MSMASKED.300

12. vbrun.300.dll

 

 
Powered by phpBB® Forum Software