26

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU wrote:

Not, well I here as though the most important expert on  and to the text

...The self-proclaimed

27

Re: Optimization of byte reading and comparing of two binary files

Kazantsev Alexey wrote:

... Self-proclaimed

:-D

28

Re: Optimization of byte reading and comparing of two binary files

Kazantsev Alexey;
on xe6 - a difference in 10 times, concatenation against filling. Though, of course, on the modern processors probably and imperceptibly especially will be on small dial-ups.

29

Re: Optimization of byte reading and comparing of two binary files

makhaon wrote:

  on xe6 - a difference in 10 times

You  concatenation in . I too . Took 10 mbytes, and concatenation, byte by byte, added by the line (s: = s + IntToHex (b, 2)). Occupied this action... 500msec. Already whole half-seconds. At  the task lasts more minutes. Well and what to it pleasure, what code complication will possible to reduce 500msec to 50?

30

Re: Optimization of byte reading and comparing of two binary files

Kazantsev Alexey;
It is clear that the main brakes there on disk operations. However and this place it is possible to refine quite.

31

Re: Optimization of byte reading and comparing of two binary files

makhaon wrote:

it is clear that the main brakes there on disk operations

Here too not the fact. Disk  too it is not simple so exists.

makhaon wrote:

however and this place it is possible to refine quite.

There is nothing to save there. It has more than losses on converting UnicodeString <> AnsiString happens.

32

Re: Optimization of byte reading and comparing of two binary files

Kazantsev Alexey;
Byte-serial reading - too not sugar. It is difficult to tell that brakes more. Is where to optimize.

33

Re: Optimization of byte reading and comparing of two binary files

Kazantsev Alexey;
Concatenation it not
Here generally except disk operations, with storage and conversions - anything is not present operation

34

Re: Optimization of byte reading and comparing of two binary files

makhaon wrote:

byte-serial reading - too not sugar.

And for this reason to save on concatenation in this case - .

SOFT FOR YOU wrote:

Concatenation it not

Repeated request on  it what in a cycle concatenation differs from a variant with preliminary reservation.

SOFT FOR YOU wrote:

Here generally except disk operations, with storage and conversions - anything is not present operation

You generally said that here lines permanently . And they  are not present. Here that that they are permanently converted, it  yes.

35

Re: Optimization of byte reading and comparing of two binary files

Kazantsev Alexey;
If I confuse nothing
That in the given code is selected 2 new lines

SStroka: = SStroka + IntToHex (ISimvol, 2);

36

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU;
On the first iteration of a cycle. Then the single line (i.e. storage under it) gradually , and the second remains invariable till the end of a cycle (since many functions  lines do not initialize result, and simply change the size. Well and if the size constant...).

37

Re: Optimization of byte reading and comparing of two binary files

In general - once again led algorithm "audit", removing "Seek" and other in the Full program...
Result which me to achieve for today - 43,7 second on two files of the exact size 9 967 616 byte.
Sampling was produced on Delphi 10.2 ( DX ) in a mode Debug (In a mode Release probably it will be faster sensitive!?)
The code I will not result yet - if who wants, I will show a bit later
The big time delays import about such operator, as:
- FOriginal. Position
- Application. ProcessMessages ;
- Probably SStroka: = SStroka + AnsiChar (ISimvol) ;
And now I would like to suggest to carry out some test of a part of the code is the very first cycle of search Zero byte in both files. The received result is there will be a Minimum time to which it is necessary to aspire at a used method of byte-serial reading! Proceeding from the received runtime it will be possible to judge runtime of the FULL program.
Now I will result the code, and you I think understand about what I!
[spoiler the Given variant uses TFileStream:]

procedure TMainForm. TestButtonClick (Sender: TObject);
var
SizeOriginal: Integer;
SizePereveden: Integer;
begin
try
StartTime: = Now;//we Fix Start time
//we Read out names of files from editing Fields (were probably edited!)
FullOriginalFileName: = FileBinOriginalEdit. Text;
FullPerevedenFileName: = FileBinPerevedenEdit. Text;
FullPerevodFileName: = DirPerevodEdit. Text + PerevodFileNameEdit. Text;
//For a variant with TFileStream
FOriginal: = TFileStream. Create (FullOriginalFileName, fmOpenRead, fmShareDenyNone);
SizeOriginal: = FOriginal. Size;
FPereveden: = TFileStream. Create (FullPerevedenFileName, fmOpenRead, fmShareDenyNone);
SizePereveden: = FPereveden. Size;
AddressFiles: = 0;
ProgressBar. Max: = SizeOriginal;
//===== Rose on the Beginning in Both files =====
FOriginal. Seek (AddressFiles, soFromBeginning);
FPereveden. Seek (AddressFiles, soFromBeginning);
while AddressFiles <= SizeOriginal-1 do
begin
FOriginal. ReadBuffer (ISimvol, 1);
FPereveden. ReadBuffer (PSimvol, 1);
Inc (AddressFiles);//Variable AddressFiles is necessary!
//we Search for Zero bytes in files in an identical position
if (ISimvol=0) and (PSimvol=0) then
begin
//Here there is a code, but is now empty
end;
end;
finally
FOriginal. Free;
FPereveden. Free;
EndTime: = Now;//we Fix STOP time
DelayTime: = SecondSpan (EndTime, StartTime);//we Calculate PROCEDURE runtime
MainMemo. Lines. Add (' Test run of files is completed! ' + #13#10 +
' test Time = ' + FloatToStr (DelayTime) + ' sec ');
end;
end;

[/spoiler]
For testing Both file were filled with bytes " FF "
Runtime - 36,29 seconds! (Theoretically - using TFileStream to accelerate it does not turn out!)
Using TBufferedFileStream in the same code - it is received 43,68 seconds.
P . S . Runtime within one minute of the Full program - I think quite normal but if to whom it is interesting - it is possible to continue and look for other variants, for example offered SOFT FOR YOU - a variant to read both files in Memory and already from there to produce reading for comparing!

38

Re: Optimization of byte reading and comparing of two binary files

Bellic;
To read from storage I offered not initially
I suggested to use CachedBuffers
Neither the first, nor you did not make the second

39

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU wrote:

Neither the first, nor you did not make the second

Well the person loves cactuses, do not hinder it smile

40

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU wrote:

Bellic;
To read from storage I offered not initially
I suggested to use CachedBuffers
Neither the first, nor you did not make the second

Ah-jaj-jaj!!!!...:-D
SOFT FOR YOU , prompt  - how to install this miracle ( CachedBuffers )?
And the author a word about connection did not write that!
Library downloaded, but in a folder sources - two files ( CachedBuffers.pas and CachedStreams.pas )!

41

Re: Optimization of byte reading and comparing of two binary files

Bellic;
You connect in uses CachedBuffers and you use
And still it seems to me, in your case it will be better such approach:

var
i: Integer;
B: Byte;
Reader: TCachedReader;
begin
Reader: = TCachedFileReader. Create (file name);
try
for i: = 0 to Reader. Limit - 1 do
begin
Reader. ReadData (B);
//ToDo
end;
finally
Reader. Free;
end;

42

Re: Optimization of byte reading and comparing of two binary files

... Copied CachedBuffers.pas and CachedStreams.pas in the directory with the Project and registered:

uses CachedBuffers, CachedStreams;

Than and how it is possible to use in each of units?
SOFT FOR YOU , I so understood is your development?
I understood so that Manual writing in it was not planned!?

43

Re: Optimization of byte reading and comparing of two binary files

Reader. Size - it is not supported!!! (Tried to apply by analogy to TFileStream th)
...
P.S. Write please a detailed manual on All interiors of Both units!!!

44

Re: Optimization of byte reading and comparing of two binary files

Reader. Seek - similarly it is not supported!!!!!!... ((((
That personal!!!
But the User is not obliged to dig in source codes in search of the correct Syntax and the put Functional!
!!!

45

Re: Optimization of byte reading and comparing of two binary files

Bellic;
I above wrote, how  smile
Instead of Size is Limit. Instead of Seek is DirectRead. If you want it is direct generally Seek - that it is necessary to be strained. Help is in README.md on project page.

46

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU wrote:

Bellic, I above wrote, how  smile
Instead of Size is Limit. Instead of Seek is DirectRead. If you want it is direct generally Seek - that it is necessary to be strained. Help is in README.md on project page.

Seek - it is not mandatory!.))
README.md found, thanks!
And on Great and Mighty, on dear (well at least, me!) Russian - the analog is available?...)
Already .)))
On the basis of test procedure the following code, above, turned out:
[spoiler]

procedure TMainForm. TestButtonClick (Sender: TObject);
var
SizeOriginal: Integer;
SizePereveden: Integer;
FROriginal: TCachedReader;
FRPereveden: TCachedReader;
begin
try
//we Read out names of files from editing Fields (were probably edited!)
FullOriginalFileName: = FileBinOriginalEdit. Text;//these files -
FullPerevedenFileName: = FileBinPerevedenEdit. Text;//were already checked
FullPerevodFileName: = DirPerevodEdit. Text + PerevodFileNameEdit. Text;
FROriginal: = TCachedFileReader. Create (FullOriginalFileName);
FRPereveden: = TCachedFileReader. Create (FullPerevedenFileName);
SizeOriginal: = FROriginal. Limit;
SizePereveden: = FRPereveden. Limit;
if SizeOriginal <> SizePereveden then
begin
ShowMessage (' Lengths of BIN-files are not equal! ' + #10#13 +
' Continuation of process of handling - Is impossible! ');
Exit;
end;
AddressFiles: = 0;
StartTime: = Now;//we Fix Start time
//===== Rose on the Beginning in Both files =====
//FROriginal. Seek (AddressFiles, soFromBeginning);
//FRPereveden. Seek (AddressFiles, soFromBeginning);
while AddressFiles <= SizeOriginal-1 do
begin
FROriginal. ReadData (ISimvol);
FRPereveden. ReadData (PSimvol);
Inc (AddressFiles);
//we Search for coincidence Zero byte
if (ISimvol=0) and (PSimvol=0) then
begin
//
end;
end;
finally
FROriginal. Free;
FRPereveden. Free;
EndTime: = Now;//we Fix STOP time
DelayTime: = SecondSpan (EndTime, StartTime);//we Calculate PROCEDURE runtime
MainMemo. Lines. Add (' Test run of files in a mode "CachedBuffers" is completed! ' + #13#10 +
' test Time = ' + FloatToStr (DelayTime) + ' sec ');
end;
end;

[/spoiler] Runtime on the same test files - 2,5 seconds !!!!
To go nuts!!! A class!!!.)))
P.S. SOFT FOR YOU , the result very much was pleasant to me, it would be desirable to study more more in detail Both libraries, I certainly will resort to help Google-, but English language sometimes happens is a little dryish and does not transfer some nuances of a Russian-speaking variant! Isn't that so?.)))

47

Re: Optimization of byte reading and comparing of two binary files

Bellic wrote:

Runtime on the same test files - 2,5 seconds !!!!
To go nuts!!! A class!!!.)))

If you still would find and compared not , and there, on 16, I am afraid to present even, as though you for such speed reacted. And without .
But, can, so it is necessary, I did not press.

48

Re: Optimization of byte reading and comparing of two binary files

SOFT FOR YOU;
Here for it

Bellic wrote:

Runtime on the same test files - 2,5 seconds !!!!
To go nuts!!! A class!!!.)))

You a box of beer of champagne (on the threshold of ) should it. For advertizing. If it is finite, both of you two - different historical persons smile

49

Re: Optimization of byte reading and comparing of two binary files

Bellic;
Dock initially was in Russian, and it was then translated to an English. A source code not to find any more. It is possible to translate docks in Google, it is possible to look demos, it is possible to write on a forum: http://www.sql.ru/forum/1178076-a/ofici … hedbuffers

50

Re: Optimization of byte reading and comparing of two binary files

Dock;
And there is a claim to me personally or to my code?