Fread performance is slow. Why?

Hello, i have a problem about fread. I don’t have any problem for fwrite but fread command is slower than it should be. How can i solve this problem?

7 comentarios

Walter Roberson
Walter Roberson el 8 de Jul. de 2019
Editada: Walter Roberson el 8 de Jul. de 2019
When I test, I find that fread() gives good performance , at least if you are not changing data type as you go, and you fread() large enough chunks.
Indicating the exact size of data to read can improve performance a bit by permitting MATLAB to pre-allocate memory.
I find that operating system and hardware issues make a much higher impact on performance
dpb
dpb el 8 de Jul. de 2019
Would have to see actual code and data being read to comment much more...as Walter says, cache misses can kill performance if you're doing something other than just reading straight chunks off disk...
Guillaume
Guillaume el 8 de Jul. de 2019
When I tested fread performance a while back, I found that a single call to fread was usually very fast. However, the performance of consecutive fread calls, with possibly some fseek in between was abysmal and it was simpler to simply read a whole file and then remove the unwanted data rather than skipping over that data with multiple fread calls.
That was a while back (R2014 IIRC), I've not checked since then.
Jan
Jan el 8 de Jul. de 2019
Editada: Jan el 8 de Jul. de 2019
@Ecem Çetinyol: Please post some example data and exact timings, because "slower than it should be" does not reveal any details. What exactly is the problem? Do you read from a local disk, network disk or a serial port object?
Ecem Çetinyol
Ecem Çetinyol el 9 de Jul. de 2019
I am reading data from a serial port object.
Jan
Jan el 9 de Jul. de 2019
Then the performance of fread depends on the speed of the transmitted data. So this is most likely either a problem of the Baud value used at opening the port, or it is a limitation of the sender. To check this, post any details: 1. the code you are using, 2. details about the connected device.
The lack of details let the readers of the forum guess, what your problem is, and this is inefficient.
Walter Roberson
Walter Roberson el 9 de Jul. de 2019
Is it a true serial port, or is it serial over USB? Serial over USB is limited to 1000 USB packets per second in the most common situations. Best performance is with sending approximately 1000 bytes per packet, and making sure that you have increased your serial port buffer sizes.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Etiquetas

Preguntada:

el 8 de Jul. de 2019

Comentada:

el 9 de Jul. de 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by