On Friday 01 June 2018 14:45:41 fredvs wrote:
> Hello Martin.
>
> I am a little afraid about the resource used by tprogressbar.
>
> Included a simple demo to show it.
> msemem.zip
> <http://mseide-msegui-talk.13964.n8.nabble.com/file/t2/msemem.zip>
>
> The tprogressbar.value is assigned by a timer with a random value:
>
> When rendering the tprogressbar: cpu used = 70 %.
>
I get 2% for msemem and 4% for Xorg, see attachment.

Some optimizations:
"
procedure tmainfo.ontimerwait(const Sender: TObject);
var
 i : int32 = 1;
 f : float ;

begin
  timerwait.Enabled := False; //<<<<not necessary

 if tag = 0 then begin  
  while i < 21 do
  begin
  f := random(100)/100;  //<<<< FPC random is slow
  tlabel1.caption := ' Random number = ' + floattostr(f);
  
  if enableview.value = true then
   TProgressBar(findcomponent('tprogressbar'+inttostr(i))).value:= f else
                     //<<<<<<< findcomponent is slow
   TProgressBar(findcomponent('tprogressbar'+inttostr(i))).value:= 0;    
  inc(i);
  end;
  timerwait.Enabled := true;  //<<<<not necessary
  
end; 
end;
"
Removing the fades probably also speeds up things.

> <http://mseide-msegui-talk.13964.n8.nabble.com/file/t2/mse_progressbar_on.p
>ng>
>
> Without rendering the tprogressbar, cpu used = 28 %.
>
> <http://mseide-msegui-talk.13964.n8.nabble.com/file/t2/mse_progressbar_off.
>png>
>
> Is there a other-less-resource-used way to mimic a  tprogressbar ?

A tchart with traces[0].chartkind = tck_bar probably is faster because it is a 
single widget instead of 20 tprogressbar.
"
procedure tmainfo.timerevent(const sender: TObject);
var
 ar1: flo64arty;
 i1: int32;
begin
 setlength(ar1,20);
 for i1:= 0 to high(ar1) do begin
  ar1[i1]:= mwcnoise() / flo64($ffffffff);
 end;
 bar.traces[0].ydata:= ar1;
end;
"
mwcnoise() is from unit msenoise.

> Do you think that drawing on a custom canvas would need less resource ?
>
Probably.

Martin
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk

Reply via email to