Показать сообщение отдельно

  #24  
Старый 06.04.2010, 15:04
AlexTheC0d3r
Постоянный
Регистрация: 25.07.2008
Сообщений: 454
Провел на форуме:
1229135

Репутация: 425
Отправить сообщение для AlexTheC0d3r с помощью ICQ
По умолчанию

Новый тест, без оптимизации...
Действительно, как бы не парадоксально это выглядело, но
PHP код:
while true do 
проигрывает по скорости коду ->
PHP код:
while 1=do 
Также можно заметить, что добавление в условие цикла сторонних вычислений во много раз замедляет его работу, вот доказательства:

PHP код:
{$OPTIMIZATION OFF}
program TestCycleDuration;

{
$APPTYPE CONSOLE}

uses
  SysUtils
DateUtils;
var
  
iinteger;
  
timeStarttimeEndTDateTime;
  
firstRessecondResthirdResstring;

begin
  Writeln
('................................');
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('First test, cycle "while true do"');
  
Writeln('Testing...');
  
:= 0;
  
timeStart := now;
  while 
True do
  
begin
    i 
:= 1;
    if 
2000000000 then
      
Break;
  
end;
  
timeEnd := Now;
  
Writeln('Test duration: ' inttostr(MilliSecondsBetween(timeEndtimeStart))
    +
    
'ms');
  
firstRes := inttostr(MilliSecondsBetween(timeEndtimeStart));
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('Second test, cycle "while 1=1 do"');
  
Writeln('Testing...');
  
:= 0;
  
timeStart := now;
  while 
do
  
begin
    i 
:= 1;
    if 
2000000000 then
      
Break;
  
end;
  
timeEnd := Now;
  
Writeln('Test duration: ' inttostr(MilliSecondsBetween(timeEndtimeStart))
    +
    
'ms');
  
secondRes := inttostr(MilliSecondsBetween(timeEndtimeStart));
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('................................');
  
Writeln('Tird test, moron'#39's cycle "while StrToInt(1)=StrToInt(1) do"');
  
Writeln('Testing...');
  
:= 0;
  
timeStart := now;
  while 
StrToInt('1') = StrToInt('1') do
  
begin
    i 
:= 1;
    if 
2000000000 then
      
Break;
  
end;
  
timeEnd := Now;
  
Writeln('Test duration: ' inttostr(MilliSecondsBetween(timeEndtimeStart))
    +
    
'ms');
  
thirdRes := inttostr(MilliSecondsBetween(timeEndtimeStart));
  
WriteLn('Two tests: 1: ' firstRes 'ms' ' 2: ' secondRes 'ms' ' 3:'
    
thirdRes 'ms');
  
Readln;
end
Результаты: 1- 4812ms 2-4750ms 3-36265ms
 
Ответить с цитированием