Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2005-12

Benchmark for FreePascal

41 messages · 12 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

darekM

Hi
I've tested some of benchmark on

http://shootout.alioth.debian.org/

I've see that reverse-complement benchmark <http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for FPC is very slow. I discover, that problem is with readln, that function consume about 90% of time. Because I use it in my program, I implemented new version of reading files. My propositions is add tTextStream to unit Classes

using is very similar

 while not eof do
    begin
      readln(s);
    end;
changed to
   tx:=tTextStream.create('name')  //or via handle
  while tx.readln(d)>=0 do
   tx.free;

My implementation cause than benchmark run 4 times faster. But I think, it need some improvements.

Is this enough to add it to Classes. If so, I'll work on it.

Darek

Reply by email

Daniël Mantione
to darekM

Op Sat, 10 Dec 2005, schreef darekM:

Show quoted text 16 lines
Hi I've tested some of benchmark on http://shootout.alioth.debian.org/ I've see that reverse-complement benchmark <http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for FPC is very slow. I discover, that problem is with readln, that function consume about 90% of time. Because I use it in my program, I implemented new version of reading files. My propositions is add tTextStream to unit Classes using is very similar while not eof do begin readln(s); end;

The Shootout benchmarks should preferably be implemented without unit classes to achieve the best memory usage results. Your code is welcome though to add to unit classes, allthough I currently can't because it uses assembler code withotu Pascal alternative, i.e. it would make the classes unit unavailable on the other processors FPC supports.

Can you do the same to improve readln?

Daniël

Reply by email

Michael Van Canneyt
to darekM: Hi I've tested some of benchmark on http://shootout.alioth.debian.org/ I've see that…
darekM wrote 9 lines
Hi I've tested some of benchmark on http://shootout.alioth.debian.org/ I've see that reverse-complement benchmark <http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for FPC is very slow. I discover, that problem is with readln, that function consume about 90% of time. Because I use it in my program, I implemented new version of reading files. My propositions is add tTextStream to unit Classes

1. You must remove the assembler from your unit.
2. Your architecture is wrong. Don't descend from TFileStream. You should create a separate TStream descendent which takes another stream as an argument in it's constructor, like the compression streams or encoding streams.
3. There is already a buffered stream (TBufStream, unit bufstream), I suggest you enhance that.
4. From 3 it follows that your unit can possibly be added to the FCL, but will certainly not make it into Classes.

Concerning the shoutout test, simply adding a
SetTextBuf(input,10000);
(or even higher) before the while loop should speed it up significantly. The default buffer is 255 chars, which is simply too small.

Can you measure the difference, and let us know ?

Anyway, glad to see that people are looking at the benchmarks :-)

Michael.

Reply by email

darekM
to Daniël Mantione: Op Sat, 10 Dec 2005, schreef darekM: The Shootout benchmarks should preferably be…

Daniël Mantione napisał(a):

Show quoted text 26 lines
Op Sat, 10 Dec 2005, schreef darekM: >Hi >I've tested some of benchmark on >http://shootout.alioth.debian.org/ > >I've see that reverse-complement benchmark ><http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for >FPC is very slow. I discover, that problem is with readln, that function >consume about 90% of time. Because I use it in my program, I implemented new >version of reading files. My propositions is add tTextStream to unit Classes > >using is very similar > >while not eof do >begin > readln(s); >end; > > The Shootout benchmarks should preferably be implemented without unit classes to achieve the best memory usage results.

For me more important is speed, in real program we always use other units

Show quoted text 6 lines
Your code is welcome though to add to unit classes, allthough I currently can't because it uses assembler code withotu Pascal alternative, i.e. it would make the classes unit unavailable on the other processors FPC supports.

I know, in code are three funcion: findendLine, findEndLine2, findEndLine3 - there are propositions, please help me to make propers compilers conditions.

Maybe strlBuf (rename to scanbuf ?) should be moved to system unit?

Can you do the same to improve readln?

readln is more complicated, is compiler function, is so small buffer (only 128 bytes) and reads char by char.
I havent any idea to do this.

Darek

Reply by email

Michael Van Canneyt
to Daniël Mantione: Op Sat, 10 Dec 2005, schreef darekM: The Shootout benchmarks should preferably be…
Daniël Mantione wrote 26 lines
Op Sat, 10 Dec 2005, schreef darekM: > Hi > I've tested some of benchmark on > http://shootout.alioth.debian.org/ > > I've see that reverse-complement benchmark > <http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for > FPC is very slow. I discover, that problem is with readln, that function > consume about 90% of time. Because I use it in my program, I implemented new > version of reading files. My propositions is add tTextStream to unit Classes > > using is very similar > > while not eof do > begin > readln(s); > end; The Shootout benchmarks should preferably be implemented without unit classes to achieve the best memory usage results. Your code is welcome though to add to unit classes, allthough I currently can't because it uses assembler code withotu Pascal alternative, i.e. it would make the classes unit unavailable on the other processors FPC supports.

Even then not. See my mail...

Can you do the same to improve readln?

The problem is not the readln implementation, but the buffer size.

Michael.

Reply by email

L505
to Michael Van Canneyt: 1. You must remove the assembler from your unit. 2. Your architecture is wrong. Don't…
Show quoted text 5 lines
Concerning the shoutout test, simply adding a SetTextBuf(input,10000); (or even higher) before the while loop should speed it up significantly. The default buffer is 255 chars, which is simply too small.

I'm also going to try this with my CPU-WARS email I sent to the mailing list a while ago, regarding StrLoadFile function comparison - thanks to Marco for suggesting this too.

Regards,
Lars

Reply by email

Daniël Mantione
to darekM: Daniël Mantione napisał(a): For me more important is speed, in real program we always…

Op Sun, 11 Dec 2005, schreef darekM:

For me more important is speed, in real program we always use other units

The Shootout is about both speed, memory and lines of code. We're no. 3 in memory usage, and if the Shootout wouldn't measure some numbers incorrectly, we would be no.1. Let's not loose that position.

I agree that speed is in many situations more important than memory, but in a lot of software, you use, i.e. text editor, memory is more important.

Show quoted text 10 lines
> Your code is welcome though to add to unit classes, allthough I currently > can't because it uses assembler code withotu Pascal alternative, i.e. it > would make the classes unit unavailable on the other processors FPC > supports. > > I know, in code are three funcion: findendLine, findEndLine2, findEndLine3 - there are propositions, please help me to make propers compilers conditions. Maybe strlBuf (rename to scanbuf ?) should be moved to system unit?

It can be moved into the strings unit, if we have also a Pascal implementation for non-i386 processors.

Show quoted text 6 lines
> Can you do the same to improve readln? > > readln is more complicated, is compiler function, is so small buffer (only 128 bytes) and reads char by char. I havent any idea to do this.

The compiler converts read/readln calls to calls to procedures in the rtl. fpc_Read_Text_ShortStr is the procedure to optimize. It is in the file text.inc.

Daniël

Reply by email

L505
Show quoted text 5 lines
> Concerning the shoutout test, simply adding a > SetTextBuf(input,10000); > (or even higher) before the while loop should speed it up significantly. I'm also going to try this with my CPU-WARS email I sent to the mailing list
// TEST 5
function StrLoadFile_test5(const FileName: string): string;
var
  F: text;
  c: char;
  str1, Line: string;
  Buf : Array[1..100000] of byte;
begin
  result:= ''; //safety
  str1:= '';
  if FileExists(FileName) = false then
    exit;
  Assign(F, FileName);   //open file
  Reset(F);
  SetTextBuf(F, Buf);
  while not Eof(F) do
  begin
    Read(F, C);
    result:= result + C;
  end;
  close(F); //close file
end;

--------------------------------------------------------- Welcome to the CPU war for StrLoadFile.. Please wait...

test 1 execution time: 9357464 <-- char by char
test 2 execution time: 257074 <-- my blockread
test 3 execution time: 265960 <-- my other blockread test 4 execution time: 2666055 <-- classes stringlist test 5 execution time: 9133218 <-- char w/buffer

Done.
Press <enter> to exit
--------------------------------------------------------

In this case, the 100,000 buffer helped a little, but not too significant.

I think stringlist.loadfile should use block reading rather than the overhead of using streams. We've got way too much overhead with stringlists using classes on top of classes on top of classes. Although the current stringlist.loadfile is much faster than char by char, block reading still beats it hands down.

Now as for Delphi's stringlist.loadfile and stringlist.text, I will have to do some tests and see.

Reply by email

L505
I think stringlist.loadfile should use block reading rather than the overhead of using streams.

Of course stringlist is an array of strings so this may not work.. time will tell

Reply by email

Jonas Maebe
to L505: // TEST 5 function StrLoadFile_test5(const FileName: string): string; var F: text; c:…
L505 wrote 20 lines
// TEST 5 function StrLoadFile_test5(const FileName: string): string; var F: text; c: char; str1, Line: string; Buf : Array[1..100000] of byte; begin result:= ''; //safety str1:= ''; if FileExists(FileName) = false then exit; Assign(F, FileName); //open file Reset(F); SetTextBuf(F, Buf); while not Eof(F) do begin Read(F, C); result:= result + C; end;

But why do you read char by Char? Why not

read(f, line);
result := result + line;

You can add a line break in between as well if you want.

close(F); //close file end;

Jonas

Reply by email

darekM
to Michael Van Canneyt: 1. You must remove the assembler from your unit. 2. Your architecture is wrong. Don't…

Michael Van Canneyt napisał(a):

Show quoted text 19 lines
On Sat, 10 Dec 2005, darekM wrote: >Hi >I've tested some of benchmark on >http://shootout.alioth.debian.org/ > >I've see that reverse-complement benchmark ><http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for >FPC is very slow. I discover, that problem is with readln, that function >consume about 90% of time. Because I use it in my program, I implemented new >version of reading files. My propositions is add tTextStream to unit Classes > > 1. You must remove the assembler from your unit.

I know, that was only propositions, I make 3 procedures.

Show quoted text 6 lines
2. Your architecture is wrong. Don't descend from TFileStream. You should create a separate TStream descendent which takes another stream as an argument in it's constructor, like the compression streams or encoding streams.

Why not descend. Why not exceed tFileStream, its natural. I want read text file in the same way like binary file.
While complicated, when it only 2 procedure should be added. Form me tTextStream should be used to fast and simple read text file (or application input stream) and no others, no allocate nor reallocate buffer. only simple read (and write).

3. There is already a buffered stream (TBufStream, unit bufstream), I suggest you enhance that.

Sorry, i don;t know about it. Its simple to implemented it.

But why it is in separated unit, nobody know about it (or to few). F.e. Lazarus has own implementation of buffering.
If we want to make faster programs, object like my should be in core unit, then everybody use them, in other case every make own implementation.

Show quoted text 5 lines
4. From 3 it follows that your unit can possibly be added to the FCL, but will certainly not make it into Classes.
Concerning the shoutout test, simply adding a SetTextBuf(input,10000);

I'll test it.

Darek

Reply by email

Marco van de Voort
to Michael Van Canneyt: Even then not. See my mail... The problem is not the readln implementation, but the…
Show quoted text 31 lines
> Op Sat, 10 Dec 2005, schreef darekM: > > > Hi > > I've tested some of benchmark on > > http://shootout.alioth.debian.org/ > > > > I've see that reverse-complement benchmark > > <http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for > > FPC is very slow. I discover, that problem is with readln, that function > > consume about 90% of time. Because I use it in my program, I implemented new > > version of reading files. My propositions is add tTextStream to unit Classes > > > > using is very similar > > > > while not eof do > > begin > > readln(s); > > end; > > The Shootout benchmarks should preferably be implemented without unit > classes to achieve the best memory usage results. Your code is welcome > though to add to unit classes, allthough I currently can't because it uses > assembler code withotu Pascal alternative, i.e. it would make the classes > unit unavailable on the other processors FPC supports. Even then not. See my mail... > > Can you do the same to improve readln? The problem is not the readln implementation, but the buffer size.

The said test has already been reviewed by Vincent aand me, however I still must dig it up and send it to shootout.

Iirc it is the speed of memory growth (the realloc) that is the problem, not the textbuffer. Exponential memgrowth.

Reply by email

Michael Van Canneyt
to darekM: Michael Van Canneyt napisał(a): I know, that was only propositions, I make 3 procedures.…
darekM wrote 29 lines
Michael Van Canneyt napisa(a): > On Sat, 10 Dec 2005, darekM wrote: > > >> Hi >> I've tested some of benchmark on http://shootout.alioth.debian.org/ >> >> I've see that reverse-complement benchmark >> <http://shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> >> for >> FPC is very slow. I discover, that problem is with readln, that function >> consume about 90% of time. Because I use it in my program, I implemented >> new >> version of reading files. My propositions is add tTextStream to unit >> Classes >> > > 1. You must remove the assembler from your unit. > I know, that was only propositions, I make 3 procedures. > 2. Your architecture is wrong. Don't descend from TFileStream. > You should create a separate TStream descendent which takes another > stream as an argument in it's constructor, like the compression streams > or encoding streams. > Why not descend. Why not exceed tFileStream, its natural. I want read text file in the same way like binary file.

Because then you must also descend THandlestream, TPipeStream, TIOStream, TDecompressionStream, TMemorystream, TDecodestream etc etc etc.

Streams are more than just for files.

While complicated, when it only 2 procedure should be added. Form me tTextStream should be used to fast and simple read text file (or application input stream) and no others, no allocate nor reallocate buffer. only simple read (and write).

It's not so simple.

Show quoted text 9 lines
> 3. There is already a buffered stream (TBufStream, unit bufstream), I > suggest you enhance that. > Sorry, i don;t know about it. Its simple to implemented it. But why it is in separated unit, nobody know about it (or to few). F.e. Lazarus has own implementation of buffering. If we want to make faster programs, object like my should be in core unit, then everybody use them, in other case every make own implementation.

Maybe, but then we should put all streams in Classes, and we're not going to do that.

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt
On Sun, 11 Dec 2005, darekM wrote: > But why it is in separated unit, nobody know about it (or to few). F.e. > Lazarus has own implementation of buffering.

Lazarus had to do a long time with FPC 1.0.x _and_ 2.0.x. Not all artefacts of that transition are already banned.

Show quoted text 5 lines
> If we want to make faster programs, object like my should be in core unit, > then everybody use them, in other case every make own implementation. Maybe, but then we should put all streams in Classes, and we're not going to do that.

Rule of thumb: specialised versions not in generically meant units, indeed.

Reply by email

darekM
to Michael Van Canneyt: Because then you must also descend THandlestream, TPipeStream, TIOStream,…

Michael Van Canneyt napisał(a):

Show quoted text 14 lines
On Sun, 11 Dec 2005, darekM wrote: > Michael Van Canneyt napisa(a): > Why not descend. Why not exceed tFileStream, its natural. I want read > text file in the same way like binary file. Because then you must also descend THandlestream, TPipeStream, TIOStream, TDecompressionStream, TMemorystream, TDecodestream etc etc etc. Streams are more than just for files.

Why must, for me my tTextStream is for readin text file, of course we may implemented readln in tBufStream

Show quoted text 8 lines
> While complicated, when it only 2 procedure should be added. Form me > tTextStream should be used to fast and simple read text file (or > application input stream) and no others, no allocate nor reallocate > buffer. only simple read (and write). It's not so simple.

It is.I've implemented it. Of course if we want to make universal bufStream then take it more work.

Show quoted text 18 lines
>> 3. There is already a buffered stream (TBufStream, unit bufstream), >> I suggest you enhance that. >> > Sorry, i don;t know about it. Its simple to implemented it. > > But why it is in separated unit, nobody know about it (or to few). > F.e. Lazarus has own implementation of buffering. > If we want to make faster programs, object like my should be in core > unit, then everybody use them, in other case every make own > implementation. Maybe, but then we should put all streams in Classes, and we're not going to do that.

But tBufStream is Owner of stream, for me is separated idea

Darek

Reply by email

darekM
to Marco van de Voort: Lazarus had to do a long time with FPC 1.0.x _and_ 2.0.x. Not all artefacts of that…

Marco van de Voort napisał(a):

Show quoted text 15 lines
>On Sun, 11 Dec 2005, darekM wrote: > > >>But why it is in separated unit, nobody know about it (or to few). F.e. >>Lazarus has own implementation of buffering. >> >> Lazarus had to do a long time with FPC 1.0.x _and_ 2.0.x. Not all artefacts of that transition are already banned.

I know history, Its only example, but this is small proof that no all know and use buffering form FPC (even if they need), FPC should have fastest implementation (it can).

Show quoted text 15 lines
>>If we want to make faster programs, object like my should be in core unit, >>then everybody use them, in other case every make own implementation. >> >> >Maybe, but then we should put all streams in Classes, and we're not going to >do that. > > Rule of thumb: specialised versions not in generically meant units, indeed.

Readln is not specialized, is rather popular function, buffering version can be used in near all programs.

Darek

Reply by email

Michael Van Canneyt
to darekM: Michael Van Canneyt napisał(a): Why must, for me my tTextStream is for readin text file,…
darekM wrote 20 lines
Michael Van Canneyt napisa(a): > > > On Sun, 11 Dec 2005, darekM wrote: > >> Michael Van Canneyt napisa(a): >> Why not descend. Why not exceed tFileStream, its natural. I want read text >> file in the same way like binary file. > > > Because then you must also descend THandlestream, TPipeStream, > TIOStream, TDecompressionStream, TMemorystream, TDecodestream > etc etc etc. > > Streams are more than just for files. Why must, for me my tTextStream is for readin text file, of course we may implemented readln in tBufStream

Pipes, Compressed Streams, IO, Decode and so on can also contain text. Your implementation requires that we re-implement your solution in all of these classes if we want to have the 'readln()' functionality available.

Show quoted text 10 lines
>> While complicated, when it only 2 procedure should be added. Form me >> tTextStream should be used to fast and simple read text file (or >> application input stream) and no others, no allocate nor reallocate >> buffer. only simple read (and write). > > > It's not so simple. It is.I've implemented it. Of course if we want to make universal bufStream then take it more work.

And that is what is needed.

Show quoted text 17 lines
>>> 3. There is already a buffered stream (TBufStream, unit bufstream), I >>> suggest you enhance that. >>> >> Sorry, i don;t know about it. Its simple to implemented it. >> >> But why it is in separated unit, nobody know about it (or to few). F.e. >> Lazarus has own implementation of buffering. >> If we want to make faster programs, object like my should be in core unit, >> then everybody use them, in other case every make own implementation. > > > Maybe, but then we should put all streams in Classes, and we're not going > to > do that. > > But tBufStream is Owner of stream, for me is separated idea

That is optional behaviour, and disabled by default.

Michael.

Reply by email

Michael Van Canneyt
to darekM: Marco van de Voort napisał(a): I know history, Its only example, but this is small proof…
darekM wrote 33 lines
Marco van de Voort napisa(a): >> On Sun, 11 Dec 2005, darekM wrote: >> > > >>> But why it is in separated unit, nobody know about it (or to few). F.e. >>> Lazarus has own implementation of buffering. >>> > > Lazarus had to do a long time with FPC 1.0.x _and_ 2.0.x. Not all artefacts > of that > transition are already banned. > I know history, Its only example, but this is small proof that no all know and use buffering form FPC (even if they need), FPC should have fastest implementation (it can). > >>> If we want to make faster programs, object like my should be in core >>> unit, then everybody use them, in other case every make own >>> implementation. >>> >> Maybe, but then we should put all streams in Classes, and we're not going >> to >> do that. >> > > Rule of thumb: specialised versions not in generically meant units, indeed. > > Readln is not specialized, is rather popular function, buffering version can be used in near all programs.

You are correct that it can and will be used in all programs.

But you are missing our main point: It should ALSO be usable for ALL kinds of streams. Your implementation currently is limited to file streams. My proposed solution makes it work for ALL streams, just as the existing (de)compression/encoding/buffer/whatever streams can be used on all streams.

So my proposal to you is to make a TTextStream = Class(TBufStream), with no assembler code. Then, and only then, can it be included in the FCL.

Michael.

Reply by email

Michalis Kamburelis
to Michael Van Canneyt

Are we talking here about making a class that can read any TStream descendant line-by-line (i.e. by simple a'la Readln method) ?

Then I believe this was already discussed on fpc-pascal, I remember that I sent there my TTextReader class implementation that does just that. TTextReader class is also part of pasdoc code right now, you can see it here
[http://cvs.sourceforge.net/viewcvs.py/*checkout*/pasdoc/pasdoc/source/component/PasDoc_ProcessLineTalk.pas].

Is this the kind of thing that is wanted ?

Michalis

Reply by email

Michael Van Canneyt
to Michalis Kamburelis
Michalis Kamburelis wrote 9 lines
Are we talking here about making a class that can read any TStream descendant line-by-line (i.e. by simple a'la Readln method) ? Then I believe this was already discussed on fpc-pascal, I remember that I sent there my TTextReader class implementation that does just that. TTextReader class is also part of pasdoc code right now, you can see it here [http://cvs.sourceforge.net/viewcvs.py/*checkout*/pasdoc/pasdoc/source/component/PasDoc_ProcessLineTalk.pas]. Is this the kind of thing that is wanted ?

Yes, with the exception that TTextReader should be a TStream descendent.

Michael.

Reply by email

darekM
to L505: // TEST 5 function StrLoadFile_test5(const FileName: string): string; var F: text; c:…

Hi
My CPU war
Welcome to the CPU war for StrLoadFile.. Please wait...

test 1 (char) execution time: 1862654
test 2 (blockread 1) execution time: 27080
test 3 (blockread fsize) execution time: 46633
test 7 (blockread tHandle) execution time: 18569
test 4 (tStringList) execution time: 364999
test 1 ln (tTextStream) execution time: 117256
test 2 ln (readln) execution time: 182298

Done.

Comment:
use Athlon 2.6G +Gentoo

test 7 : read file via tFileStream -- this is the fastest way to read file

test 2 ln : read file line by line used: readln and eof test 1 ln: read file line by line used tTextStream

Darek

Show quoted text 30 lines
--------------------------------------------------------- Welcome to the CPU war for StrLoadFile.. Please wait... test 1 execution time: 9357464 <-- char by char test 2 execution time: 257074 <-- my blockread test 3 execution time: 265960 <-- my other blockread test 4 execution time: 2666055 <-- classes stringlist test 5 execution time: 9133218 <-- char w/buffer Done. Press <enter> to exit -------------------------------------------------------- In this case, the 100,000 buffer helped a little, but not too significant. I think stringlist.loadfile should use block reading rather than the overhead of using streams. We've got way too much overhead with stringlists using classes on top of classes on top of classes. Although the current stringlist.loadfile is much faster than char by char, block reading still beats it hands down. Now as for Delphi's stringlist.loadfile and stringlist.text, I will have to do some tests and see. _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email

L505
to darekM
Show quoted text 15 lines
test 1 (char) execution time: 1862654 test 2 (blockread 1) execution time: 27080 test 3 (blockread fsize) execution time: 46633 test 7 (blockread tHandle) execution time: 18569 test 4 (tStringList) execution time: 364999 test 1 ln (tTextStream) execution time: 117256 test 2 ln (readln) execution time: 182298 Done. Comment: use Athlon 2.6G +Gentoo test 7 : read file via tFileStream -- this is the fastest way to read file

Neat!
I'm testing on a Celeron 400 using Winblows 2000.. Do you have the source code for test 7 so we can run it through different CPU architectures?

L505

Reply by email

L505
Do you have the source code for test 7 so we can run it through different CPU architectures?

nevermind, my bad, I see the email attachment.

Reply by email

Marco van de Voort
to L505
> Do you have the source code for test 7 so we can run it through different CPU > architectures? nevermind, my bad, I see the email attachment.

Since the maillists are a bit irregular, I want to repeat the point that the relative slowliness of the revcomp benchmark is the repeated realloc, not the reading of the textfile (though a small settextbuf might improve it a bit).

Reply by email

L505
to Jonas Maebe: But why do you read char by Char? Why not read(f, line); result := result + line; You can…
Show quoted text 12 lines
But why do you read char by Char? Why not read(f, line); result := result + line; You can add a line break in between as well if you want. > close(F); //close file > end; Jonas

Yes tried that, and on my computer readln with string concatenation actually locks up the computer (only on big files.. not on small)! Something is wrong with the string concatenation... I'll dig up some old FPC-Pascal mailing archives to show you what I mean.

Actually on my computer reading char by char was faster than line by line! I am not sure what is wrong with the string concatenation.. but I commented out the concatenation and that was definitely the problem. As suggested by Vincent S. I tried putting it in brackets too... i.e.

result + (line + #13#10);

and it didn't help the speed of the concatenation by any significant amount.

In my next post I will send you some links to the archives which discussed some of this if I can find them.

Lars

Reply by email

L505
Show quoted text 7 lines
> But why do you read char by Char? Why not > > read(f, line); > result := result + line; In my next post I will send you some links to the archives which discussed some of this if I can find them.

After trying Vincent's suggestion I did not see noticeable improvement. On the large MB file I tried, my computer locks up doing string concentration. Actually, it doesn't lock up.. it just takes several hours to complete.

Lars

p.s. sorry DarekM if I'm stealing your post. But maybe some of this is related to the benchmarks if there is any concatenation in any of the benchmarks

Reply by email

L505
to darekM: Hi My CPU war Welcome to the CPU war for StrLoadFile.. Please wait... test 1 (char)…
Athlon 2.6G +Gentoo

Here are tests on a Celeron 400 Windows 2000 then

Welcome to the CPU war for StrLoadFile.. Please wait...

test 1 (char) execution time: 9287434
test 2 (blokread 1) execution time: 267230
test 3 (blockread fsize) execution time: 262710
test 7 (blokread tHandle) execution time: 265247
test 4 (tStringList) execution time: 2660387
test 1 ln (tTextStream) execution time: 624126
test 2 ln (readln) execution time: 831215

It appears the new Athlon processor takes extreme advantage of tHandle (test 7) while an old Celeron doesn't. Or, unless it is Linux versus Windows. I guess we can tell that test7, test3 and test2 are fastest so far.

Reply by email

darekM
to Marco van de Voort: Since the maillists are a bit irregular, I want to repeat the point that the relative…

Marco van de Voort napisał(a):

Show quoted text 6 lines
Since the maillists are a bit irregular, I want to repeat the point that the relative slowliness of the revcomp benchmark is the repeated realloc, not the reading of the textfile (though a small settextbuf might improve it a bit).

Its not true. Realloc is invoked only few times. Most of times consume readln. You may try remove all lines from revcom except readln, and then see, that time of computation has near 80% of prev. From the second side, i remove only readln (pass only const string) and revcom speed has 4 times faster.

Darek
.

Reply by email

Vincent Snijders
to darekM
darekM wrote 15 lines
Marco van de Voort napisał(a): > Since the maillists are a bit irregular, I want to repeat the point that > the relative slowliness of the revcomp benchmark is the repeated > realloc, not the reading of the textfile (though a small settextbuf > might improve it > a bit). > > Its not true. Realloc is invoked only few times. Most of times consume readln. You may try remove all lines from revcom except readln, and then see, that time of computation has near 80% of prev. From the second side, i remove only readln (pass only const string) and revcom speed has 4 times faster.

Did you test with files > 10 MB?

Vincent

Reply by email

Marco van de Voort
to Vincent Snijders
Show quoted text 17 lines
> Marco van de Voort napisa?(a): > >> Since the maillists are a bit irregular, I want to repeat the point that >> the relative slowliness of the revcomp benchmark is the repeated >> realloc, not the reading of the textfile (though a small settextbuf >> might improve it >> a bit). >> >> > Its not true. Realloc is invoked only few times. Most of times consume > readln. You may try remove all lines from revcom except readln, and then > see, that time of computation has near 80% of prev. From the second > side, i remove only readln (pass only const string) and revcom speed has > 4 times faster. > Did you test with files > 10 MB?

.. and on *nix ? (since that is where the benchmarks run)

Reply by email

Jonas Maebe
to darekM: Hi I've tested some of benchmark on http://shootout.alioth.debian.org/ I've see that…
darekM wrote
I've see that reverse-complement benchmark <http:// shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for FPC is very slow. I discover, that problem is with readln, that function consume about 90% of time.

In my test (Mac OS X/PPC, rtl and program compiled with register variables, text buffer of 64kb) readln's overheid is negligible. The large cost comes from writeln. The reason the C version is so much faster is because its output is buffered as well. We automatically flush the output after each writeln (i.e. after each writeln of 60 characters), while in C this only happens at the very end of the program for 128kb of characters at a time.

Jonas

Reply by email

Marc Weustink
to Jonas Maebe
Jonas Maebe wrote 16 lines
On 10 dec 2005, at 22:09, darekM wrote: > I've see that reverse-complement benchmark <http:// > shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for > FPC is very slow. I discover, that problem is with readln, that > function consume about 90% of time. In my test (Mac OS X/PPC, rtl and program compiled with register variables, text buffer of 64kb) readln's overheid is negligible. The large cost comes from writeln. The reason the C version is so much faster is because its output is buffered as well. We automatically flush the output after each writeln (i.e. after each writeln of 60 characters), while in C this only happens at the very end of the program for 128kb of characters at a time.

Another speed improvement will be disabling IO checks for write, {$I-}

I normally wouldn't recomend doing so, but for this test it either passes or fails.

Marc

Reply by email

Jonas Maebe
to Marc Weustink
Marc Weustink wrote 9 lines
> In my test (Mac OS X/PPC, rtl and program compiled with register > variables, text buffer of 64kb) readln's overheid is negligible. > The large cost comes from writeln. The reason the C version is so > much faster is because its output is buffered as well. We > automatically flush the output after each writeln (i.e. after > each writeln of 60 characters), while in C this only happens at > the very end of the program for 128kb of characters at a time. Another speed improvement will be disabling IO checks for write, {$I-}

That code only takes 0.5% of the time, not really relevant.

Jonas

PS: my "negligible" above was an overstatement, the readln code takes up 8.4% of the time. Still a far cry from 90% though.

Reply by email

Marc Weustink
to Jonas Maebe
Jonas Maebe wrote 16 lines
On 14 dec 2005, at 18:33, Marc Weustink wrote: >> In my test (Mac OS X/PPC, rtl and program compiled with register >> variables, text buffer of 64kb) readln's overheid is negligible. >> The large cost comes from writeln. The reason the C version is so >> much faster is because its output is buffered as well. We >> automatically flush the output after each writeln (i.e. after each >> writeln of 60 characters), while in C this only happens at the very >> end of the program for 128kb of characters at a time. > > > Another speed improvement will be disabling IO checks for write, {$I-} That code only takes 0.5% of the time, not really relevant.

OK, in some other benchmarks I got a (imo) serious ~10-20% speed improvement by doing so (and all pieces help:)

Marc

Reply by email

Michael Van Canneyt
to Jonas Maebe: In my test (Mac OS X/PPC, rtl and program compiled with register variables, text buffer…
Jonas Maebe wrote 14 lines
On 10 dec 2005, at 22:09, darekM wrote: > I've see that reverse-complement benchmark <http:// > shootout.alioth.debian.org/benchmark.php?test=revcomp&lang=all> for FPC > is very slow. I discover, that problem is with readln, that function > consume about 90% of time. In my test (Mac OS X/PPC, rtl and program compiled with register variables, text buffer of 64kb) readln's overheid is negligible. The large cost comes from writeln. The reason the C version is so much faster is because its output is buffered as well. We automatically flush the output after each writeln (i.e. after each writeln of 60 characters), while in C this only happens at the very end of the program for 128kb of characters at a time.

Normally, You can speed that up considerably by doing the following:

program testp;
uses dos; // Needed for TextRec...
Var
  F : Text;
  Buf : Array[1..100000] of char;
  I : Integer;
begin
  Assign(F,'');
  Rewrite(F);
  SetTextBuf(F,Buf); // Allocate HUGE buffer
  TextRec(F).FlushFunc:=Nil; // Disable flushing after each writeln().
  For I:=1 to 10000 do
    Writeln(F,'teststring');
  Close(F); // Will flush.
end.

If you strace that, you'll see that the whole buffer is written to screen in one big gulp, instead of 256 chars per write.

In fact, I think maybe we should do the

  TextRec(F).FlushFunc:=Nil; // Disable flushing after each writeln().

In SetTextBuf if the file is open for writing, as otherwise the settextbuf is meaningless. Or add a DisableFlushText() call to the system unit. (to avoid dragging the Dos unit in if you want this)

Michael.

Reply by email

Marco van de Voort
to Michael Van Canneyt

(small post note in this discussion:

a customer complained that his app was a lot slower (till 3 times) with D2006/FastMM.

I'm still investigating, and it seems that somehow FastMM must more often copy when reallocating than the old MM for large blocks (big as in the 100kbs or even MB size)

)

Reply by email

Florian Klaempfl
to Marco van de Voort
Marco van de Voort wrote 8 lines
(small post note in this discussion: a customer complained that his app was a lot slower (till 3 times) with D2006/FastMM. I'm still investigating, and it seems that somehow FastMM must more often copy when reallocating than the old MM for large blocks (big as in the 100kbs or even MB size)

I really wonder how FastMM made it in D2006. All memory managers are a mess because of its complexity but FastMM is hell with the assembler code. Borland should have better spent time in an improved compiler and use a good documented memory manager written in pascal.

Reply by email

Florian Klaempfl
to Ales Katona: Did I get it right that the new FastMM in new delphi is 3 times slower than the old…
Ales Katona wrote 21 lines
Marco van de Voort wrote: > (small post note in this discussion: > > a customer complained that his app was a lot slower (till 3 times) with > D2006/FastMM. > > I'm still investigating, and it seems that somehow FastMM must more often > copy when reallocating than the old MM for large blocks (big as in > the 100kbs or even MB size) > > > ) > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel > > > Did I get it right that the new FastMM in new delphi is 3 times slower than the old delphi one (which is on par with FPC AFAIK)

Well, the old Delphi one was usually much slower than FPC's.

?

Reply by email

Ales Katona
to Marco van de Voort: (small post note in this discussion: a customer complained that his app was a lot slower…
Marco van de Voort wrote 17 lines
(small post note in this discussion: a customer complained that his app was a lot slower (till 3 times) with D2006/FastMM. I'm still investigating, and it seems that somehow FastMM must more often copy when reallocating than the old MM for large blocks (big as in the 100kbs or even MB size) ) _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Did I get it right that the new FastMM in new delphi is 3 times slower than the old delphi one (which is on par with FPC AFAIK)?

Reply by email