Text.Write speed - Delphi 5 / Delphi 2006 [Edit]

Hi !

I have speed troubles for using Text.Write method in Delphi 2006, particularly with distant files (local network).
For example, with the following code ("F" is a text file ; "Line" is an about 200-character string):

-----
  AssignFile(F, FileName);
  try
    Rewrite(F);
    for l := 1 to 100 do
      begin
        for c := 1 to Length(Line) do
          Write(F, Line[c]);
        Writeln(F);
      end;
  finally
    CloseFile(F);
  end;
-----

On a distant file:
Delphi 5 -> 0.08 seconds
Delphi 2006 -> close to 8 seconds

Is there a specific reason for this?

Best regards,
Adrien

Edited by: Adrien Pincivy on Apr 27, 2009 8:06 AM
0
Adrien
4/27/2009 3:07:11 PM
embarcadero.delphi.win32 2183 articles. 0 followers. Follow

8 Replies
1328 Views

Similar Articles

[PageSpeed] 32

Adrien Pincivy wrote:

> Hi !
> 
> I have speed troubles for using Text.Write method in Delphi 2006,
> particularly with distant files (local network).  For example, with
> the following code ("F" is a text file ; "Line" is an about
> 200-character string):
> 
> -----
>   AssignFile(F, FileName);
>   try
>     Rewrite(F);
>     for l := 1 to 100 do
>       begin
>         for c := 1 to Length(Line) do
>           Write(F, Line[c]);
>         Writeln(F);
>       end;
>   finally
>     CloseFile(F);
>   end;
> -----
> 
> On a distant file:
> Delphi 5 -> 0.08 seconds
> Delphi 2006 -> close to 8 seconds
> 
> Is there a specific reason for this?

Yes. I don't remember why, but Borland changed the textfile I/O to
write any output to the file immediately instead of buffering it. This
does have the advantage that written content will not get lost if the
app crashes or does not close the file properly, but it has a massive
effect on throughput speed.
On a local file this is more or less compensated by the OS file
caching, but on remote files this is not the case since OS does not
cache writes to these files, as far as I know, to reduce the chance of
data loss when the network connection breaks.

Here is some code from my archives you can test to see if it fixes your
problem:

reintroducing output buffering for textfiles in D2006

{code: Delphi}

program Project2;
{$APPTYPE CONSOLE}
uses
  windows, SysUtils;

type
  TFarProc = procedure;

Function DevOut( Var F: TTextRec ): Integer;
  Begin { DevOut }
    Result := 0;
    With F Do
      If BufPos > (BufSize * 9 div 10) Then Begin
        if FileWrite(F.Handle, BufPtr^, BufPos) < 0 then
          Result := GetLastError;
        BufPos := 0;
      End; { If }
  End; { DevOut }


procedure test;
var
  outfile: Text;
  x: Integer;
  buffer: array [1..$10000] of Byte;
begin
  assignfile(outfile, 'c:\temp\delphi5.txt');
  SetTextBuf(outfile, Buffer);
  rewrite(outfile);
  TTextRec(outfile).FlushFunc := TTextRec(outfile).InOutFunc;
  TTextRec(outfile).InOutFunc := @DevOut;
  for x := 1 to 5000000 do begin
    write(outfile, IntToStr(x) + '-');
    if x MOD 1000 = 0 then
      writeln(outfile, DateTimeToStr(Now));
  end;
  closefile(outfile);
end;

procedure TimeRoutine(aProc: TFarProc);
var
  T1, T2: Cardinal;
begin
  T1 := GetTickCount;
  aProc;
  T2 := GetTickCount;
  writeLn(#13#10, 'Took ', T2-T1, ' ticks');
end;

begin
  Timeroutine(Test);
  Write('Hit enter to close');
  ReadLn;
end.


-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
0
Peter
4/27/2009 5:37:09 PM
Hi Peter!

Thanks for your answer and explanations: adding a homemade buffer corrects the problem indeed :)

Do you know from which Delphi version this modification has been implemented?
Is there an option (TApplication, compiling option...) in order to enable again the default use of a buffer? (there seems not...)

Thanks again.
Adrien

(May I transmit this solution to the other forums where I asked the same question?)
0
Adrien
4/28/2009 9:34:35 AM
Adrien Pincivy wrote:

> Hi Peter!
> 
> Thanks for your answer and explanations: adding a homemade buffer
> corrects the problem indeed :)
> 
> Do you know from which Delphi version this modification has been
> implemented? 

Delphi 2006 as far as I know. I have never looked at Delphi 2005,
however.

> Is there an option (TApplication, compiling option...)
> in order to enable again the default use of a buffer? (there seems
> not...)

No, sorry. 

> 
> (May I transmit this solution to the other forums where I asked the
> same question?)

Of course. 



-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
0
Peter
4/28/2009 5:43:06 PM
Thanks for all !

Adrien
0
Adrien
4/29/2009 7:21:30 AM

    
0
Adrien
4/29/2009 4:26:17 PM
(sorry, double post...)
0
Adrien
4/29/2009 4:33:19 PM
Adrien Pincivy wrote:

> Seems to be all good...
> 
> Just have a last (I hope!) question:
> Why "If BufPos > (BufSize * 9 div 10)" and not "If BufPos = BufSize"
> in the DevOut function?

I don't remember exactly why I coded it this way, sorry. There was
probably a reason but I have no idea which it was <g>. Just try the
alternative and see whether it causes any problems.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
0
Peter
4/29/2009 6:17:17 PM
I had no problem for the moment... I'm going to make more tests, but I'll probably go for more security too.

Thanks!

Adrien
0
Adrien
5/5/2009 7:20:41 AM
Reply:

Similar Artilces:

Webaccess 5.5 to 6.5 Speed
Has anyone seen an increase in speed of Webaccess after upgrading from 5.5 to 6.5 over dial up? Our 5.5. webaccess is too slow and unfortunately recommendations from the TID's didn't help. We are looking to upgrade our mail system and I want to get feedback Thanks in advance. Chris Chris wrote: > > Has anyone seen an increase in speed of Webaccess after upgrading from 5.5 > to 6.5 over dial up? Our 5.5. webaccess is too slow and unfortunately > recommendations from the TID's didn't help. We are looking to upgrade our > mail s...

editable text box + write to file
I'm working on a small content management system. Right now, what I want is to be able to read from a text file (rand.txt), dump the contents already in the text file into a multiline textbox, allow the user to edit the text, then overwrite the prexisting file on submit. Here is the code I have so far: <%@ Import Namespace="System.IO" %> <script language="vb" runat="server"> sub Page_Load(sender as Object, e as EventArgs) Dim FILENAME as String = Server.MapPath("Rand.txt") Dim sr As StreamReader = New Strea...

Use of 'cut' in regexps; speed in 5.5.3 v 5.5.63
Below is a program that investigates a problem in combinatorics of words; it spends most of its time checking for disallowed subsequences, so that for example if an earlier sequence includes '0120', later substrings must not match /0.*1.*2.*0/. I've added a termination point at length 400 to facilitate timing (which means I'm looking for sequences of up to 200 digits), and found two things to surprise me. Firstly, 5.005_03 runs nearly twice as fast as 5.005_63 for both the testcases; secondly, I had thought to get a minor speedup using the (?>...) 'cut' mec...

5.5 Speed Problem
We have two users at the same site connecting, in single user mode, to a database. The users have identical PCs running NT 4.0 SP5. All queries on one of the PCs run approximately 7 times slower that on the other PC. The application is written in Power++. We are running SQL Anywhere 5.5.03 build 1666. All other programs run on both PCs at the same speed. The two users have identical ODBC dlls. Netbios has been disabled on both PCs. The PCs have identical background tasks running. Accessing the database on the local PC, rather than the network, does not affect performan...

Speed of 5.5.04
I am re-posting the question below. I asked it previously but did not get an answer. I hope I have been succinct and clear. It is important to myself and the client that I get an answer. Will somone address this please? I had an interesting experience this past week. I had not yet received my 16 pack of SQLAW but did have SQLAW installed locally but pointing to a database on a network drive. The client is using Netware 3.12. I am using PowerBuilder as the front end. I ran a report in PowerBuilder that is normally very taxing on the network. Still, I got an answer back in a...

Speed of 5.5.02
Has anybody noticed a performance degradation after moving to 5.5.02 from 5.5.01 of SQLA. On a NT3.51 server. Our version is build #1495, is this the one with all fixes? or is there a later version? Getting a lot of ear-bashing from users, any help appreciated. Thanks. This is a multi-part message in MIME format. --------------39BAFA14734C3F94BD216A74 Content-Type: text/plain; charset=us-ascii Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Transfer-Encoding: 7bit Carl- No I havent noticed a performance loss. Can you explain more?? As ...

Writing a Word / Text like editing tool.
Does anyone know if it is possible to write a word-like text editing tool with ASP.NET? As part of the functionality there would be a screen where the user would load in patient info from an existing database and then the user would fill in the details and save this as a letter preferably in XML format. The editor tool needs to have all the text formatting functions that word has and also a spellchecking tool and autotext. Is this possible? Also is it possible to link with spell checker in office and word? Are you looking for a WYSIWIG? google that issue: http://www.google.com/search...

Speed Speed Speed
Name: Arthur A Lilford Email: arthuratposdriversdotcodotza Product: Firefox Summary: Speed Speed Speed Comments: Thanks Speed is great that is what gets me happy Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

In rich text editor I cannot normally edit text just after pasting text
Name: Darek Email: darekatgrapevinejobsdotcodotuk Product: Firefox Summary: In rich text editor I cannot normally edit text just after pasting text Comments: In rich text editor I have following problem: After pasting text for example from Word I try to remove a letter or word from just pasted text and I could not do this. If I insert let say single space then after this operation I am able to remove text and generally do everything. Browser Details: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5....

10.5 rich text edit control
Does any one know if these are known issues that may be fixed in 10.5.1? - When I print a rich text edit control (PrintEx), the input field values change to "??". - When I save a document with rte_1.SaveDocument, if the cursor is in the header, the header text becomes the detail text and the detail and footer text disappear. - If I right-click an input field and change the data value in the properties dialog, the change doesn't apply. ...

Missing scrollbar on rich text edit PB6.5
sorry for submitting this request again. i tried replying to the reply but i don't think it worked. in any event - Roy Kiesler tells me to check the vertical scrollbar property, but i cannot find that. I doubleclick on the treeview and bring up the properties window, expecting to find it under the general tab but it's not there. i get my horizontal scrollbar without doing anything extra. i really need a vertical scrollbar. thanks in advance. I'm confused. Your message subject says "rich text edit', and your message says 'treeview'. What kind of ...

superreview granted: [Bug 112922] Ability to edit and split #text nodes : [Attachment 223616] edit text nodes v1
neil@parkwaycc.co.uk <neil@httl.net> has granted Jason Barnabe (np) <jason_barnabe@fastmail.fm>'s request for superreview: Bug 112922: Ability to edit and split #text nodes https://bugzilla.mozilla.org/show_bug.cgi?id=112922 Attachment 223616: edit text nodes v1 https://bugzilla.mozilla.org/attachment.cgi?id=223616&action=edit ------- Additional Comments from neil@parkwaycc.co.uk <neil@httl.net> > set subject(aObject) > { >+ // the node value's textbox won't fire onchange when we change subjects, so >+ // let's fire ...

superreview requested: [Bug 112922] Ability to edit and split #text nodes : [Attachment 223616] edit text nodes v1
Jason Barnabe (np) <jason_barnabe@fastmail.fm> has asked neil@parkwaycc.co.uk <neil@httl.net> for superreview: Bug 112922: Ability to edit and split #text nodes https://bugzilla.mozilla.org/show_bug.cgi?id=112922 Attachment 223616: edit text nodes v1 https://bugzilla.mozilla.org/attachment.cgi?id=223616&action=edit ------- Additional Comments from Jason Barnabe (np) <jason_barnabe@fastmail.fm> This patch makes the text node view editable. The changes will be reflected onchange (which happens once the textbox loses focus after a change). Undo/Redo from the Ed...

Rich Text Edit page size pb 6.5
How is the default page size for a rte object changed from 8.5 x 11? We need 8.27 x 11.69 (metric A4) for European users. I've found no property, function or event in any of the PB doc that will accomplish this. RTE controls are tightly linked to the printer selection of the PC. What you could do is set the default paper size for the default printer to be A4 (or you can prgramatically change it via API call) On Wed, 18 Jun 2003 10:50:20 -0400, in powersoft.public.powerbuilder.objects <GJ> wrote: >How is the default page size for a rte object changed from 8.5 x 11...

Problems with jConnect 5.5 and text columns in ASE 12.5.3
Hi, we run an application connected via jConnect 5.5 and config property JAVA_VERSION=6 to an ASE 12.5.2 EBF 12054 ESD#2. Everything worked fine. Now we tried to move the database to an ASE 12.5.3 EBF 12144 and got in trouble with inserts in text columns. The text values are cut after 8112 characters. When we run jConnect without the JAVA_VERSION=6 property the insert into the text columns work fine but we cannot use varchar(>256) anymore. Besides, the ASE metadata are changed a little bit. Has anybody had the same problem with the text columns and a clue for a workaround/sol...

Web resources about - Text.Write speed - Delphi 5 / Delphi 2006 [Edit] - embarcadero.delphi.win32

Delphi - Wikipedia, the free encyclopedia
... an archaeological site and a modern town in Greece on the south-western spur of Mount Parnassus in the valley of Phocis . The site of Delphi ...

Delphi Automotive (@DelphiAuto) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Delphi Automotive @ DelphiAuto ...

Delphi Connect for Verizon on the App Store on iTunes
Get Delphi Connect for Verizon on the App Store. See screenshots and ratings, and read customer reviews.


Audi working with Delphi to develop autonomous car tech
Audi is developing an iPad-sized device that will pack all the necessary computing power for a self-driving car

US approves China company's acquisition of Delphi biz
The Committee on Foreign Investment in the United States has formally approved the acquisition of Delphi's global production of braking systems ...

Verizon And Delphi Officially Launch Vehicle Diagnostics Service - $250 For The Module, $5 A Month On ...
If you're a car nut, a paranoid parent, or a small business owner looking to do a little, uh, company vehicle economy analysis, Verizon's teamed ...

Watch out Google: Delphi gives Ars a ride in its self-driving car
The automotive components maker gave Ars a preview ride around the neighborhood. MOUNTAIN VIEW, CA—On Thursday morning I met with Delphi at its ...

The skinny on Delphi's autonomous road trip across the United States
Filed under: Green , Videos , Autonomous Last week, Delphi's autonomous car became the first to complete a coast-to-coast trip across the United ...

Delphi partners with WiTricity on automated wireless charging system
One could easily argue that parking between the white lines at any local hangout presents a challenge for some inexperienced drivers. So, why ...

Resources last updated: 11/24/2015 2:26:55 PM