Question

I am working on a test application on Android platform. Test the write/read speed to the sdcard. I write in C language with NDK interface.

First I write a for-loop to create 256 files with 512 random bytes in each. This part works fine. I open file with flag O_CREAT|O_WRONLY|O_SYNC and mode 0666. After call write, I do sync() to make sure the data is written on the card.

Then I write another 2-level for-loop to read these file to test speed. I use O_RDWR|O_SYNC to open the file. Then call read().

Here is the thing: If it is the first time I run the read part. The first loop to read take more time than the after. I'm sure it is because after the first loop, program read the cache not the real physical card.

I've tried O_DIRECT flag to read. But it error with EINVAL. In the man page for open, it says maybe it is because of this function not implement by the platform.

Do you have any idea on how to read with no-cache in Android?

Was it helpful?

Solution

You may need a rooted phone to disable operating-system-level caching.

http://wiki.cyanogenmod.com/index.php?title=SDCardSpeedTests

That also takes care to do operations large enough to overwhelm any on-card buffers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top