Why would saving to a folder called temp cause data loading to slow down in a for loop in Matlab?

后端 未结 2 1945
清歌不尽
清歌不尽 2021-02-14 10:05

IMPORTANT UPDATE

I just made the discovery that after restarting Matlab and the computer, this simplified code no longer reproduces the problem for me either... I am so

2条回答
  •  时光说笑
    2021-02-14 10:50

    There are two things here

    1. Storage during a for loop is an expensive operation as it usually opens a file stream and closes it before it moves on. You might not be able to avoid this.
    2. Second thing is speed of storage and its cache speed. Most likely programs use temp folder for its own temporary files and have a garbage collector or software looking after these to clean them. If you start opening and closing file stream to this folder you have to send a request to get exclusive write access to the folder. This again adds to the time.

    If you are doing image processing operations and you have multiple images you can run into a bottle neck with writing to hard drive due to its speed, cache and current memory available to MATLAB.

提交回复
热议问题