|
Sepulchre, I was correct...
By going console mode - I literally got a HUGE performance boost & gigantic orders of magnitude speed increase!
(W/ some variances - Especially if I cutoff tty console outputs (radical & ugly, & no indicator of progress thru the array of entries from the file... but speed was what I was after, after all, & I got that, bigtime, thru that same cutting down of 1,498,232 lines of non-normalized text data into a 533,000++ lines of text data in my custom HOSTS file))
Down from near 2 minute mark to ONLY 10 seconds, via this code:
================================================== ==
{COPYRIGHT APK - Alexander Peter Kowalski 06/01/2008 onwards}
program APKHostsFileRewriterConsoleModeApp;
//Have this down to 11 second runtimes in consolemode/DOS tty mode
//(w/ no screen outputs that is (It is slower with them @ around 30 seconds))... apk
//MUCH FASTER THAN GUI MODE MODEL WHICH TAKES JUST UNDER 2 MINUTES... apk
{$define nodebug}
{$STACKCHECKS OFF}
{$D-} //will prevent placing Debug info to your code.
{$L-} //will prevent placing local symbols to your code.
{$O+} //will optimize your code, remove unnecessary variables etc.
{$Q-} //removes code for Integer overflow-checking.
{$R-} //removes code for range checking of strings, arrays etc.
{$S-} //removes code for stack-checking. USE ONLY AFTER HEAVY TESTING !
{$Y-} //will prevent placing smybol information to your code
{$H-} //Forces ShortString usage (no heap usage) until password routine... apk
{$APPTYPE CONSOLE}
uses
SysUtils, StrUtils, Windows;
//I eliminated the "uses" dependency on the Forms class object units by NOT using Application.Handle
//& instead stepping right down to the clean Win32 API code again for ProcessID + ProcessHandle
//To be able to set this application's parent thread to REALTIME CPU Usage & also its child
//thread (1 of 2) active to realtime when/if needed too... apk
{$H-}
var
Ch: ShortString;
F1:TextFile;
F2:TextFile;
Flags:TReplaceFlags;
Counter:Integer;
ThreadHandle: THandle;
ProcessID: DWORD;
ProcessHandle: THandle;
begin;
ProcessID:= GetCurrentProcessID;
ProcessHandle:= OpenProcess(PROCESS_SET_INFORMATION, false, ProcessID);
SetPriorityClass(ProcessHandle, REALTIME_PRIORITY_CLASS);
ThreadHandle:= GetCurrentThread;
SetThreadPriority(ThreadHandle, THREAD_PRIORITY_TIME_CRITICAL);
//---------------------------------------
//"ACTIVE INGREDIENT"/ENGINE HERE:
//---------------------------------------
try
Counter:=0;
AssignFile(F1, 'HOSTSFromFranceToInsert.txt');
Reset(F1);
AssignFile(F2, 'B:\HOSTS\NewNormalizedFinalMinusTrailingBlanksNEW EST.txt');
Rewrite(F2); //Blanks it out, so no need for FileUtils unit If FileExists stuff... apk
writeln(F2, Trim('Start Time = ' + Trim(TimeToStr(Now))));
while not Eof(F1) do
begin
Try
Counter:=Counter+1;
Readln(F1, Ch);
//writeln(IntToStr(Counter)); (GOOD FOR DEBUG, BUT, WRITES TO CONSOLE SCREEN slows execution to 40 seconds... apk}
//clrscr; {Nice for seeing it on same line updating, rather than row after row... apk}
Ch:= StringReplace(Ch, '127.0.0.1 ', '0.0.0.0 ', Flags); //vs. Spybot inserts of 127.0.0.1(TAB)URL{cr+lf}
Ch:= StringReplace(Ch, '127.0.0.1', '0.0.0.0', Flags);
Ch:= ReverseString(Ch); //StrRev C/C++ equivalent... apk
Ch:= StringReplace(Ch, ' ', '', Flags);
Ch:= ReverseString(Ch);
Ch:= StringReplace(Ch, '0.0.0.0', '0.0.0.0 ', Flags);
Ch:= StringReplace(Ch, '0.0.0.0 ', '0.0.0.0 ', Flags);
//Still considering a FOR loop here 1-4 interations... apk
Ch:= StringReplace(Ch, '"', '', Flags);
Ch:= StringReplace(Ch, '"', '', Flags);
Ch:= StringReplace(Ch, '"', '', Flags);
Ch:= StringReplace(Ch, '"', '', Flags);
//This extra FINALLY costs me around 3-5 seconds too, but worth it for data commit integrity... apk
finally
Writeln(F2, Trim(Ch));
end;
//---------------------------------------
//USING EXCESSIVE TRIMS, THOUGH GOOD FOR CODE SECURITY & DATA INTRGRITY TO AN EXTENT, SLOWS RUNTIME
//Up to 24 second levels, via lines much like this one below as an example:
//Ch:= StringReplace(Trim(Ch), Trim('0.0.0.0'), '0.0.0.0 ', Flags);
//Ch:= StringReplace(Trim(Ch), Trim('127.0.0.1'), Trim('0.0.0.0'), Flags);
//Ch:= StringReplace(Ch, Trim('"'), '', Flags);
//---------------------------------------
end;
//writeln(F2, Trim('End Time = ' + Trim(TimeToStr(Now))));
writeln(F2, 'End Time = ' + TimeToStr(Now));
//writeln(F2, Trim('Records Processed = ' + Trim(IntToStr(Counter))));
writeln(F2, 'Records Processed = ' + IntToStr(Counter));
CloseFile(F2);
Flush(F2); //clear memory buffer for output file... apk
CloseFile(F1);
Flush(F1); //clear memory buffer for input file... apk
except //CUSTOM EXCEPTION ABEND/ERR HANDLER I CREATED... apk
begin
CloseFile(F2);
Flush(F2); //clear memory buffer for output file... apk
CloseFile(F1);
Flush(F1); //clear memory buffer for input file... apk
exit;
end;
end;
end.
================================================== ==
apk
__________________
"I'm Reese: Sgt. TechComVN38416, assigned to protect you - You've been TARGETTED FOR TERMINATION!"
Last edited by APK; Jun 28, 2008 at 10:52pm.
|