We have a case where we have 30+ instances of text in an RTF document that need to be replaced with specific database values.The routine we have does work, but it's pretty slow.In one case, we have a 1+ meg file, that we need to do the 30 replacements on via the REPLACENOCASE function.This file is
With a 1meg+ file, you want it sub 10 seconds?
I think you're hoping for far too much... Think about that the OS has to
pass that file to CF, which for a file of that size, is going to take
more than 10 seconds anyway
Try opening a 1meg+ file in Notepad - it'll take a LOT more than 10
seconds
1) Use Replace() instead of ReplaceNoCase(), as it's much faster
2) Recreate your loop and replacing, etc, with cfscript instead of tags
3) Your elements to replace, if you are using a list and list functions like
listGetAt(), etc, switch it to an array
After that, if you still need more speed,
If you don't need the case-insensitivity of ReplaceNoCase(), you might try
ReplaceList() instead.This will eliminate the loop.Not sure how much
you'll gain in speed, but letting CF loop over the elements should be faster
than doing it yourself.
- Original Message -
From: Shawn Grover
If you're on a Windows platform, I have some CFX tags that may be of help.
Just experimenting, I can alter a 1.3Mb file in under 4 seconds with the
following code.
cfx_readLn Filename=C:\Test.txt Name=ReadLn Direction=TTB
cfset MyQuery = QueryNew(Line)
cfloop query=ReadLn
cfset
I think another option would be ReplaceList(). Although the function
itself loops sequentially, maybe there's a gain to be had by using a
native function rather than a hand-crafted loop, but I dunno. It'd be
easy to benchmark, anyway.
(On second thought, ReplaceList is implicitly scoped to all,
On my tests I've found that doing the following with each particular piece
of text seems to speed the process up as the FindNoCase is substantially
quicker than the ReplaceNoCase if the particular sub-string doesn't exist in
the original text. Using the code below, the whole process completes in
7 matches
Mail list logo