Silvio a Beccara wrote:
Hi, the code is short, so I think I can attach it here. It uses both dynamic and static arrays, but to my surprise the difference in time is slight.
<snip>
for i := 1 to mn do begin for j := 1 to mn do begin r1 := random; matrdyn ^[ i, j ] := r1; end; end;
This code spends most of execution time in random number generation (instead of storing just add all the random numbers, and compare with time to store a constant). AFAIK GPC has high quality, but moderate speed random number generator. If you need a lot of random numbers you should investigate more carefully available options -- you can easily find fast low-quality generators, but low-quality random numbers my ruin your results :(
The second main ingredient is linear scan trough memory. Such scan is slow -- you spend most time waiting for data from memory (even if you write). The code GPC generates for that scan is slow, but that slowness is masked by memory access.