Alright so i read that trunc is "slow" so I did some testing. Interestingly enough it is.
There is a little about a 3% +/- change each time i ran it. Anway:Code:procedure TForm1.Button1Click(Sender: TObject); var endTick: integer; count: integer; i: integer; j: real; begin edit1.Text := 'started'; j := 2.4; endTick := GetTickCount + 5000; count := 0; repeat i := trunc(j); count := count + 1; until (getTickCount > endTick); edit1.Text := intToStr(count); end;
RoundL = a function using the round below
RoundO = a created object with a function using the round below
Trunc = 183,419,960 / ~5000 = 36,683/ms
Round(j - 4.9999999999) = 266,647,840 / ~5000 = 53,329/ms
RoundL = 157,383,577 / ~5000 = 31,376/ms
RoundO = 168202037 / ~5000 = 33,640/ms
So basically to get speed i have to manually type the round function in each spot i need to use it. It sounds crazy but it seems to be the only solution i've found.
Bookmarks