Anonymous user
Elementary cellular automaton/Random number generator: Difference between revisions
Elementary cellular automaton/Random number generator (view source)
Revision as of 09:14, 1 August 2019
, 4 years ago→{{header|Pascal}}: Freepascal knows ROR and ROL using 64 Bit on 64-Bit Oprating system is fast
m (→{{header|Pascal}}: Freepascal knows ROR and ROL using 64 Bit on 64-Bit Oprating system is fast) |
|||
Line 308:
=={{header|Pascal}}==
{{Works with|Free Pascal}}
Fast only in 64 Bit.
<lang pascal>Program Rule30;
//http://en.wikipedia.org/wiki/Next_State_Rule_30;
//http://mathworld.wolfram.com/Rule30.html
{$IFDEF FPC}
{$Mode Delphi}
{$OPTIMIZATION ON,ALL}
{$CODEALIGN proc=8}
Line 326 ⟶ 325:
maxRounds = 2*1000*1000;
rounds = 10;
CpuF = 3.7e9; // Ryzen 5 1600 Turbo 3.7 Ghz
var
{$ALIGN 32}
Rule30_State :
procedure InitRule30_State;inline;
begin
Rule30_State
end;
function BinStr(Zahl:
var
i : integer;
Line 371 ⟶ 351:
procedure Out_Rule30_State;
var
tmpState : Uint64;
i : integer;
tmp : array[0..7] of byte;
begin
//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;
procedure Next_State_Rule_30;inline;
var
run, prev,next: Uint64;
begin
run := Rule30_State;
Prev := RORQword(run,1);
next := ROLQword(run,1);
Rule30_State := (next OR run) XOR prev;
end;
procedure Speedtest;
Line 434 ⟶ 382:
i,j,b: NativeInt;
Begin
writeln('Speedtest for statesize of ',
//Warm up start Turbo of CPU
For j := 10*1000*1000-1 downto 0 do
Next_State_Rule_30;
InitRule30_State;
T0 := time;
For i := maxRounds-1 downto 0 do
Line 450 ⟶ 394:
For j := 7 downto 0 do
Begin
b := (b+b) OR (Rule30_State
Next_State_Rule_30
end;
end;
Line 472 ⟶ 416:
For j := 7 downto 0 do
Begin
b := (b+b) OR (Rule30_State
Next_State_Rule_30
end;
write(b:4);
end;
writeln;
end;
Line 484 ⟶ 427:
SpeedTest;
Task;
write(' <ENTER> ');readln;
end.</lang>
{{out}}
<pre>
//running compiled for 64-BIT
Speedtest for statesize of 64 bits
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
231_11100111 204_11001100 6_00000110 122_01111010 253_11111101 204_11001100 220_11011100 230_11100110
2000000 calls take 00:00:00.109
cycles per Byte : 201.65
The task
220 197 147 174 117 97 149 171 100 151
<ENTER>
</pre>
=={{header|Perl}}==
|