
06.04.2010, 15:04
|
|
Постоянный
Регистрация: 25.07.2008
Сообщений: 454
Провел на форуме: 1229135
Репутация:
425
|
|
Новый тест, без оптимизации...
Действительно, как бы не парадоксально это выглядело, но проигрывает по скорости коду -> Также можно заметить, что добавление в условие цикла сторонних вычислений во много раз замедляет его работу, вот доказательства:
PHP код:
{$OPTIMIZATION OFF}
program TestCycleDuration;
{$APPTYPE CONSOLE}
uses
SysUtils, DateUtils;
var
i: integer;
timeStart, timeEnd: TDateTime;
firstRes, secondRes, thirdRes: string;
begin
Writeln('................................');
Writeln('................................');
Writeln('................................');
Writeln('................................');
Writeln('First test, cycle "while true do"');
Writeln('Testing...');
i := 0;
timeStart := now;
while True do
begin
i := i + 1;
if i = 2000000000 then
Break;
end;
timeEnd := Now;
Writeln('Test duration: ' + inttostr(MilliSecondsBetween(timeEnd, timeStart))
+
'ms');
firstRes := inttostr(MilliSecondsBetween(timeEnd, timeStart));
Writeln('................................');
Writeln('................................');
Writeln('................................');
Writeln('................................');
Writeln('Second test, cycle "while 1=1 do"');
Writeln('Testing...');
i := 0;
timeStart := now;
while 1 = 1 do
begin
i := i + 1;
if i = 2000000000 then
Break;
end;
timeEnd := Now;
Writeln('Test duration: ' + inttostr(MilliSecondsBetween(timeEnd, timeStart))
+
'ms');
secondRes := inttostr(MilliSecondsBetween(timeEnd, timeStart));
Writeln('................................');
Writeln('................................');
Writeln('................................');
Writeln('................................');
Writeln('Tird test, moron'#39's cycle "while StrToInt(1)=StrToInt(1) do"');
Writeln('Testing...');
i := 0;
timeStart := now;
while StrToInt('1') = StrToInt('1') do
begin
i := i + 1;
if i = 2000000000 then
Break;
end;
timeEnd := Now;
Writeln('Test duration: ' + inttostr(MilliSecondsBetween(timeEnd, timeStart))
+
'ms');
thirdRes := inttostr(MilliSecondsBetween(timeEnd, timeStart));
WriteLn('Two tests: 1: ' + firstRes + 'ms' + ' 2: ' + secondRes + 'ms' + ' 3:'
+ thirdRes + 'ms');
Readln;
end.
Результаты: 1- 4812ms 2-4750ms 3-36265ms
|
|
|