[fpc-devel] Benchmark for FreePascal
L505
fpc505 at z505.com
Sun Dec 11 17:28:34 CET 2005
> > 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.
More information about the fpc-devel
mailing list