Anonymous user
Elementary cellular automaton/Random number generator: Difference between revisions
Elementary cellular automaton/Random number generator (view source)
Revision as of 09:53, 1 August 2019
, 4 years ago→{{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
<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;▼
result[1] :='_';▼
Begin▼
end;
Line 375 ⟶ 343:
next := ROLQword(run,1);
Rule30_State := (next OR run) XOR prev;
▲end;
function NextRule30Byte:NativeInt;
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
Begin
writeln('Speedtest for statesize of ',64,' bits');
//Warm up start Turbo of CPU
For
Next_State_Rule_30;
Line 390 ⟶ 371:
T0 := time;
For i := maxRounds-1 downto 0 do
NextRule30Byte;
▲ b := (b+b) OR (Rule30_State AND 1);
T1 := time;
writeln(NextRule30Byte);
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
Begin
writeln('The task ');
InitRule30_State;
For k := 1 to rounds
▲ b := (b+b) OR (Rule30_State AND 1);
▲ write(b:4);
writeln;
end;
Line 433 ⟶ 399:
//running compiled for 64-BIT
Speedtest for statesize of 64 bits
44
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
2000000 calls take 00:00:00.
cycles per Byte :
The task
|