[Gambas-user] Question about read/write file performance

Benoît Minisini gambas at ...1...
Sat Nov 27 02:42:45 CET 2010


> Hi,
> 
> Maybe this is a basic question. I have 2 scripts like this:
> 
> Code 1:
> Dim buff as *Byte*
> sizeOfFile = Stat("aBigFile").Size
> 
> hFile = Open "aBigFile" for read
> For i = 1 to sizeOfFile
> Read hFile, buff
> Next
> Close hFile
> 
> Code 2:
> Dim buff as *Byte*
> Dim bigBuff as *Float*
> 
> sizeOfFile = Stat("aBigFile").Size
> 
> hFile = Open "aBigFile" for read
> For i = 1 to sizeOfFile / 8
> Read hFile, bigBuff
>  Next
> For i = 1 to sizeOfFile MOD 8
> Read hFile, buff
> Next
> Close hFile
> 
> Code 1 take t1 time unit to finish, code 2 is t2.
> 
> Are t1, t2 different? Which can be faster?

Reading/writing data is always faster if you read it chunk by chunk instead of 
reading it byte by byte. The chunk size is usually 4096 bytes, which is the 
size of a memory page on a common Linux system. You won't see much gain with 
higher values.

Try and check!

Regards,

-- 
Benoît Minisini




More information about the User mailing list