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
around 15 seconds. It's not sub 10 seconds but it is pretty close. Certainly
better than 3 to 5 minutes.


The example file I used was 1.3Mb consisting of 18875 lines (Undernet
channel dump) therefore the loop runs 18875 times...
     
  <cfx_readLn Filename="C:\Test2.txt" Name="ReadLn" Direction="TTB">
  <cfscript>
   MyQuery = QueryNew("NewLine");
   QueryAddRow(MyQuery, CFX_ReadLn.LineCount);
   for(counter = 1; counter LTE CFX_ReadLn.LineCount; counter = counter + 1)
{
    tmpLine = ReadLn.Line[counter];  

     if (FindNoCase(" Text to replace ", tmpLine))
           tmpLine = ReplaceNoCase(tmpLine, " Text to replace ", "My new
text", "ALL");
   
     <!--- snip (another 28 if statements...) --->


     if (FindNoCase(" Different stuff to replace ", tmpLine))
           tmpLine = ReplaceNoCase(tmpLine, " Different stuff to replace ",
"Some other text", "ALL");


    QuerySetCell(MyQuery, "NewLine", tmpLine, counter);
   }
  </cfscript>
  <cfx_query2file query="MyQuery" filename="C:\result.txt" nocolumnlist>

The benchmarks I get are as follows (all times are in ms)


A - ReadLn
B - Loop
C - Query2File


                    A        B         C
Iteration 1    131    14490    311   
Iteration 2    130    14312    300
Iteration 3    130    14352    310
Iteration 4    130    14501    311
Iteration 5    130    14500    331


Average       130    14431    313


Thats roughly 0.79 seconds per line.


If I run the code without the FindNoCase statements, the whole process takes
on average 9 seconds longer to complete.


Paul
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to