I made some cpp app that make statistics on i/o operations on external sd card in Android device.
I noticed that if I open file for read purpose it take few tens microseconds – for example 138 microseconds and for write purpose it takes 5265 microseconds, which is 38 times bigger.
Why is that?
EDIT: in the ‘O_WRONLY’ case – the file is not exist before.
My specific code looks like:
int fd = open(file_name, O_RDONLY);
And
int fd = open(tmp_name,O_CREAT|O_TRUNC|O_WRONLY);
Truncation means probably modifying SD Card contents. If the truncated file is very large this could take some time.
File creation involves a write to SD Card anyway, so it definitely is slower than just reading. Another factor, which influences write speed, is the SD Card’s age. If there have been many writes, even small ones, the search for a new unused block could consume quite some time.