isa
isa

Reputation: 1085

TBitmap SaveToFile Seems Slow in windows 10

I run the same code below on Multi-boot machine windows 7 and windows 10, and the benchmarks show slow SaveToFile operation in Windows 10

Windows 10 500, 953, 875, 688, 578, 750, 453

Windows 7 109, 125, 109, 110, 125, 140, 125


var
  I, Tick: integer;
  Bitmap: TBitmap;
begin
  Bitmap := TBitmap.Create;
  Bitmap.SetSize(500,500);
  Bitmap.PixelFormat := pf24bit;
  Bitmap.Canvas.Brush.Style:= bsDiagCross;
  Bitmap.Canvas.Brush.Color:= clRed;
  Tick := GetTickCount;
  for I := 0 to 100 do
  begin
    SetBkColor(Bitmap.Canvas.Handle, RGB(random(255),random(255),random(255)));
    Bitmap.Canvas.FillRect(Rect(0, 0, 500, 500));
    Bitmap.SaveToFile(IntToStr(I)+'.bmp');
  end;
  ShowMessage(IntToStr(GetTickCount-Tick));
  Bitmap.Free;
end;

I think SaveToFile works different in windows 10 it waits till all bitmaps are saved, in case of windows 7 it works like background task, if that is true how to make SaveToFile works as in windows 7.

Update

as @ForguesR mentioned the slow down comes from Windows 10 defender after disabling it, I got better result 187, 171, 172, 178, 188, 156, 187 , Windows 7 defender does not affect saving, I don't know about windows 8. Is there API or a way to stop windows 10 defender from checking and slowing saving operation?

Upvotes: 1

Views: 263

Answers (1)

ForguesR
ForguesR

Reputation: 3618

You are running the same program on the same hardware but with a different OS. Starting from there it was obvious that there was something in Windows 10 slowing it down. As you found out, by disabling Windows 10 Defender you get almost the same performance.

Fortunately, you can not "control" an antivirus from your code. If that would be possible spreading a virus would be an easy task.

Upvotes: 1

Related Questions