Anonymous user
Elementary cellular automaton/Random number generator: Difference between revisions
Elementary cellular automaton/Random number generator (view source)
Revision as of 07:50, 30 July 2019
, 4 years ago→{{header|Pascal}}: make ist comparable to D two million tests
(added assembler optimized pascal version) |
m (→{{header|Pascal}}: make ist comparable to D two million tests) |
||
Line 308:
=={{header|Pascal}}==
{{Works with|Free Pascal}}
Use 32-Bit assembler for speed like in Delphi-forum years ago.Sometimes it helps.<BR>Speedtest only for Next_State_Rule_30, no extraction of Bits like in D [http://rosettacode.org/wiki/Elementary_cellular_automaton/Random_Number_Generator#D] with 8x2E6 calls.
<lang pascal>Program Rule30;
//https://www.entwickler-ecke.de/viewtopic.php?t=111812▼
//http://en.wikipedia.org/wiki/Next_State_Rule_30;
//http://mathworld.wolfram.com/Rule30.html
▲//https://www.entwickler-ecke.de/viewtopic.php?t=111812
{$IFDEF FPC}
{$Mode Delphi}
Line 324:
SysUtils;
const
maxRounds =
rounds = 10;
Line 330:
const
RULE30_BITSIZE =
SizeOfRegister = SizeOf(NativeUint);
Line 355:
Rule30_State[i] := 0;
end;
function BinStr(Zahl: Uint32): String;
Line 370 ⟶ 369:
end;
procedure
var
i : integer;
Line 414 ⟶ 413:
RCL ECX,1 // shift MSB into LSB
BT EDI,0 //
MOV EDX,EAX
RCR EDX,1 // shift LSB into MSB
Line 422 ⟶ 421:
MOV Dword Ptr [EBX],ECX; // save
ADD EBX,SizeOfRegister // next Pos
MOV ECX,EAX // running to previous
MOV EAX,EDI // next to running
Line 428 ⟶ 427:
POP EDI;POP ESI;POP EBX;
end;// ['EBX','ESI','EDI'];
procedure Speedtest;
var
T1,T0 : TDateTime;
i,j,b: NativeInt;
Begin
writeln('Speedtest for statesize of ',RULE30_BITSIZE,' bits');
InitRule30_State;
T0 := time;
For i := 8*maxRounds-1 downto 0 do
dummy(@Rule30_State[0]);
T1 := time;
Line 444 ⟶ 443:
// Takte pro Durchlauf
writeln('cycles per call : ',((T1-t0)*86400*CpuF)/(maxRounds):0:2);
Out_Rule30_State;
T0 := time;
For i := maxRounds-1 downto 0 do
Begin
Next_State_Rule_30(@Rule30_State[0]);▼
b := 0;
For j := 7 downto 0 do
Begin
b := (b+b) OR (Rule30_State[0] AND 1);
▲ Next_State_Rule_30(@Rule30_State[0]);
end;
end;
T1 := time;
Out_Rule30_State;
writeln(maxRounds,' calls take ',FormatDateTime('HH:NN:SS.zzz',T1-T0));
writeln('cycles per
writeln;
end;
Line 479 ⟶ 485:
Task;
readln;
end.</lang>
{{out}}
<pre>
Dummy calls 00:00:00.
cycles per call :
0_00000000 0_00000000 0_00000000 0_00000000 0_00000000 0_00000000 0_00000000 1_00000001D_00000000
206_11001110 118_01110110 103_01100111 126_01111110 188_10111100 192_11000000 103_01100111 206_11001110D_11001110
cycles per
The task
|