type speeds

Started by
0 comments, last by Mav 21 years, 1 month ago
the delphi helpfile says by using the generic variable types (integer, cardinal) you would get the highest performance. this makes kind of sense since integer and cardinal are 32 bit which fits to the processor. but is it really slower to use byte variables or word or shortint.. isn''t it faster to compare two 8 bit values in an if-statement than comparing two 32 bit values?
Advertisement
Create a new Delphi project. Drop a button and two labels onto your form, and paste the following code into the button''s OnClick event:


  var  LastTickCount: Cardinal;  Counter: Cardinal;  A1, B1: Byte;  A2, B2: Cardinal;begin  LastTickCount := GetTickCount;  A1 := 5;  B1 := 6;  A2 := 5;  B2 := 6;  while GetTickCount < LastTickCount + 1000 do  begin    if B1 > A1 then      Inc(Counter);  end;  Label1.Caption := IntToStr(Counter);  Counter := 0;  LastTickCount := GetTickCount;  while GetTickCount < LastTickCount + 1000 do  begin    if B2 > A2 then      Inc(Counter);  end;  Label2.Caption := IntToStr(Counter);  


Label1 will display the number of Byte-comparisons done in one second, Label2 will display the number of Cardinal-comparisions done in one second.

I dunno how representative this test is, but for me it does more Byte-comparisons than Cardinal-comparisons.

This topic is closed to new replies.

Advertisement