Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-08

File write speed and random function

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jürgen Hestermann

I wrote a small (GUI) program with Delphi which tests the performance writing to a file on a drive. It creates a file and then writes "random" numbers to it. I have the following array:

var CopyArray : array[1..25000] of LongInt;

which I fill with numbers in a loop and then write it to disk with BlockWrite:

for i := low(CopyArray) to high(CopyArray) do
    CopyArray[i] := random(10000);
BlockWrite(Datei,CopyArray,sizeof(CopyArray),geschrieben);

(This loop is put in another loop to get different file sizes (multiples of sizeof(CopyArray))). Time is measured to calculate the transfer rate. This works on Delphi and I also can run it under Lazarus (with some minor changes around the UI).

But there is a significant performance difference between the Delphi version and the Lazarus version: The Delphi version is always about 11% faster than the Lazarus version (independent from the transfer rate). I found out that if I change the assignment to CopyArray using a constant as in

for i := low(CopyArray) to high(CopyArray) do
    CopyArray[i] := 77777;

then this difference disappears (so this speeds up the file writing by 10%)! If I do the same in the Delphi version there are no changes in the transfer rates.

I don't know why that happens because this slowdown appears on all tranfer rates (30 MB/s or 10 MB/s). If the random function eats up performance (more than the same in Delphi) then this effect should be less or invisible on slow disk transfer rates because the program overhead disappears in relation to total times. But that does not happen.

Any ideas?

Reply by email

JoshyFun
to Jürgen Hestermann

Hello Lazarus,

Monday, August 17, 2009, 7:37:21 PM, you wrote:

JH> for i := low(CopyArray) to high(CopyArray) do
JH>     CopyArray[i] := random(10000);
JH> for i := low(CopyArray) to high(CopyArray) do
JH>     CopyArray[i] := 77777;

Measure the time of both routines performing it 100 or 1000 times. I'm quite sure that the random function is the problem itself. Disk caches will hide facts because the second write will be processed after the random numbers are being generated and confuse the tests, so isolate both processes.

Best regards, JoshyFun

Reply by email