Jump to content

Elementary cellular automaton/Random number generator: Difference between revisions

m
→‎{{header|Pascal}}: changed, so that the output ist comparable to C and GO -> 44 at 2000000
m (→‎{{header|Pascal}}: Freepascal knows ROR and ROL using 64 Bit on 64-Bit Oprating system is fast)
m (→‎{{header|Pascal}}: changed, so that the output ist comparable to C and GO -> 44 at 2000000)
Line 308:
=={{header|Pascal}}==
{{Works with|Free Pascal}}
Using ROR and ROL is nearly as fast as assembler and more portable.<BR>[https://tio.run/##7VVtc5pAEP7Or9gPmUFTIpCkaQq1M8aXxBkDVMn05UuGwKk34sFwR0zM5K/X7oEYNfYXtH7Au9vdZ5/dvd1LAx4G8ck4DVcrL0smWTCHYR6TM8NWdH0qRGrpOmGNBZ3RlEQ0aCTZRJc73SFP4n4kAkHupcX9jsk8ENNFksVRY5HEY0RthMlcL5EbUzGPlZejfq/T7UHPa78qAC9Ht0lEoEPidErLA9fz@7f9Xy2/7zrgOlprMHhFD1LUdjvd1qB/7UCaJWHzUhu4rtc0XxG1Oxh1S/uW5/k/vS60XWfkDrqF0On0e69KzglHldEzvxM05rYSJowLPJkHT8MkZxGHJpwem4ZhFB8bRVl5jr8mmMVJO817uDlrfCKfbUBiw@clYfARzAvDAD/PHhIphOvpUlEegwz9l5zPTiXBMhllBsGCO8rExbmtKDIiEuUZgT6jYlvLpiymjNjKA5lQtgdhIS1bISzagThQpApEMsKwcqZhEsmjxlD1jUblAuUAiL3DA889NCnO3eE3LHRUk0BmXYokUCka7It2YpY6tULZHUo/dfiBC8mlimOcs1DQhBVhlLZXzxiqEwj6SPpM2MpVxZPwPBYFZlmuci9dlMsP5V9dOqvt8Gg5HUB6h@7zf5x/E2e/jUYpIZEgXFRt45uab2DX@h208@m86AlqwYGbucioIDGrqRsQGCcZcOmR0yWBZAyqdnGuqfBABVeLRtH170E2hzyVeplYTxPUbHt3KO4hAJVBmsbblDoxIUoWTCRg4EKRo@pQbCh4N1hkRIbEE@tQpIPSw2Yk/gX@rS0LFHMbpQp9V6@@LdrAY/j4EsUcRDAjmBBkgI9Ild6aenNjOY41GjWWy6Wq@eaJb9R3kNTwOYwJh5RkIN1gdVStVkNNYdSPLy/OMU1yZNf1jU/LsE63Md4X3g/4rKr5zAIcjmRCsgPF9acEmfMZlPU7lOEip7OiaoBZXD8o61QWQHuJss4PkatcF9fJL@4krHlWMCp86Tp@d/hVsslIEK2tG6vV73AcBxO@OnHP/gA Try it online!] I don't know the CPU-frequency.Runtime about 57 ms for 2 million
Fast only in 64 Bit.
 
<lang pascal>Program Rule30;
//http://en.wikipedia.org/wiki/Next_State_Rule_30;
Line 316 ⟶ 315:
{$Mode Delphi}
{$OPTIMIZATION ON,ALL}
{$CODEALIGN proc=8,LOOP=1}
{$ELSE}
{$APPTYPE CONSOLE}
Line 334 ⟶ 333:
begin
Rule30_State:= 1;
end;
 
function BinStr(Zahl: Uint64): String;
var
i : integer;
begin
setlength(result,9);
result[1] :='_';
For i := 0 to 7 do
begin
result[7-i+2] := chr(Zahl AND 1+Ord('0'));
Zahl := Zahl shr 1;
end;
end;
 
procedure Out_Rule30_State;
var
tmpState : Uint64;
i : integer;
tmp : array[0..7] of byte;
begin
tmpState := Rule30_State;
//SwapEndian(tmpState); //does not work
For i := 0 to 7 do
Begin
tmp[i] := Byte(tmpState);
tmpState := tmpState SHR 8;
end;
For i := 7 downto 0 do
write(tmp[i]:4,BinStr(tmp[i]));
writeln;
end;
 
Line 375 ⟶ 343:
next := ROLQword(run,1);
Rule30_State := (next OR run) XOR prev;
end;
 
function NextRule30Byte:NativeInt;
Begin
result[1] :='_' 0;
bresult := (bresult+bresult) OR (Rule30_State AND 1);Next_State_Rule_30;
bresult := (bresult+bresult) OR (Rule30_State AND 1);Next_State_Rule_30;
result := (result+result) OR (Rule30_State AND 1);Next_State_Rule_30;
result := (result+result) OR (Rule30_State AND 1);Next_State_Rule_30;
result := (result+result) OR (Rule30_State AND 1);Next_State_Rule_30;
result := (result+result) OR (Rule30_State AND 1);Next_State_Rule_30;
result := (result+result) OR (Rule30_State AND 1);Next_State_Rule_30;
result := (result+result) OR (Rule30_State AND 1);Next_State_Rule_30;
end;
 
Line 380 ⟶ 361:
var
T1,T0 : TDateTime;
i,j,b: NativeInt;
Begin
writeln('Speedtest for statesize of ',64,' bits');
//Warm up start Turbo of CPU
For ji := 10*1000*1000-1 downto 0 do
Next_State_Rule_30;
 
Line 390 ⟶ 371:
T0 := time;
For i := maxRounds-1 downto 0 do
NextRule30Byte;
Begin
b := 0;
For j := 7 downto 0 do
Begin
b := (b+b) OR (Rule30_State AND 1);
Next_State_Rule_30;
end;
end;
T1 := time;
writeln(NextRule30Byte);
Out_Rule30_State;
writeln(maxRounds,' calls take ',FormatDateTime('HH:NN:SS.zzz',T1-T0));
writeln('cycles per Byte : ',((T1-t0)*86400*CpuF)/maxRounds:0:2);
Line 407 ⟶ 381:
procedure Task;
var
k,j,b: integer;
Begin
writeln('The task ');
InitRule30_State;
For k := 1 to rounds do
write(b:4NextRule30Byte);
Begin
b := 0;
For j := 7 downto 0 do
Begin
b := (b+b) OR (Rule30_State AND 1);
Next_State_Rule_30;
end;
write(b:4);
end;
writeln;
end;
Line 433 ⟶ 399:
//running compiled for 64-BIT
Speedtest for statesize of 64 bits
44
231_11100111 204_11001100 6_00000110 122_01111010 253_11111101 204_11001100 220_11011100 230_11100110
2000000 calls take 00:00:00.049
cycles per Byte : 90.65
 
The task
220 197 147 174 117 97 149 171 100 151
<ENTER>
 
//running compiled for 32-BIT
Speedtest for statesize of 64 bits
44
231_11100111 204_11001100 6_00000110 122_01111010 253_11111101 204_11001100 220_11011100 230_11100110
2000000 calls take 00:00:00.109108
cycles per Byte : 201199.6580
 
The task
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.