Reputation: 27296
I'm doing some comparisons between the performance of the standard VCL TImage
control and various other third-party alternatives. I'm using GetTickCount
to measure how long it takes for the image to load. In reality it takes about 4 seconds, however LoadFromFile()
returns almost immediately to my surprise!
procedure TfrmMain.Button1Click(Sender: TObject);
begin
FStart:= GetTickCount;
imgStandard.Picture.LoadFromFile(txtFilename.Text);
FEnd:= GetTickCount; //<-- Put a breakpoint here to observe immediate return in debug
lblStandard.Caption:= IntToStr(FEnd-FStart)+' Msec';
end;
Loading the same JPEG file in both the image controls visually takes just as long as, for example, comparing with the TImage32
from Graphics32. Both block the UI during this time as expected, at about 4 seconds. The GR32 reports, for example, 3734 Msec, while the standard one only reports 16 Msec.
Why does this happen? How can I accurately measure the time it takes for the image to really load into a TImage
?
Upvotes: 3
Views: 385
Reputation: 613432
Why does this happen?
The difference between the two controls is to do with how the decompression is handled.
Almost all of the time taken for your image is for the decompression step, which explains the the discrepancy in your timings.
How can I accurately measure the time it takes for the image to really load into a
TImage
?
You could insert a call to imgStandard.Update
immediately following the call to LoadFromFile
, which would force a paint cycle, and hence force the decompression step.
Upvotes: 6