Main Site Documentation

Storage (SD/USB) Speed


#1

Storage write and read speed depends on many factors. These include the brand, internal USB/SD card buffers, fragmentation, file system type, cluster formatting size and several others. Giving an estimate is almost impossible!
Fragmentation can make a big difference. The more fragmented your storage is, the more jumping around the file system has to do and this might affect the speed by 2, 4 factors or even more. So you have to avoid it.
To get the best performance, start with a formatted storage media and then write data sequentially in bigger chunks. Nothing crazy, 1024 bytes is fine.

Here’s a test of the speed:
-Format your storage on the PC.
-Make sure you have the latest SDK and firmware.
-Run this program:

// Use USB or SD Memory?
 #define USB

using System;
using System.Threading;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.IO;
using Microsoft.SPOT.IO;
using GHIElectronics.NETMF.IO;
using GHIElectronics.NETMF.USBHost;

namespace Test
{
    public class Program
    {
        static void Main()
        {
            const int BUFFER_SIZE = 1024*4;
            const int TOTAL_FILE_SIZE = 1024 * 1024;
            byte[] buffer = new byte[BUFFER_SIZE];
            DateTime start_time;
            DateTime end_time;
            TimeSpan ts;
            int i;

            // set some data
            for (i = 0; i < buffer.Length; i++)
                buffer[i] = (byte)i;

 #if USB
            while (USBHostController.GetDevices().Length == 0)
                ;

            PersistentStorage ps = new PersistentStorage(USBHostController.GetDevices()[0]);
 #else
           PersistentStorage ps = new PersistentStorage("SD");
 #endif

            ps.MountFileSystem();

            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;

            Debug.Print("Looking for file \"Test.dat\" and deleting it if exists.");
            if(File.Exists(rootDirectory + @ "\Test.dat"))
                File.Delete(rootDirectory + @ "\Test.dat");

            Debug.Print("Testing write...");
            FileStream FileHandle = new FileStream(rootDirectory + @ "\Test.dat", FileMode.Create, FileAccess.Write);

            start_time = DateTime.Now;
            for (i = 0; i < TOTAL_FILE_SIZE / BUFFER_SIZE; i++)
            {
                FileHandle.Write(buffer, 0, buffer.Length);
            }
            end_time = DateTime.Now;
            ts = end_time - start_time;

            Debug.Print("Write Speed >>>");
            Debug.Print("Total time: " + ts.ToString());
            Debug.Print("Total time in seconds: " + ((float)ts.Ticks / TimeSpan.TicksPerSecond).ToString() + " seconds");
            Debug.Print("Speed: " + (((float)1024) / ((float)ts.Ticks / TimeSpan.TicksPerSecond)).ToString() + " KBytes/s");

            FileHandle.Close();

            // Flush everything to make sure we are starting fresh.
            ps.UnmountFileSystem();
            Thread.Sleep(1000);
            ps.MountFileSystem();

            Debug.Print("Testing read...");
            FileHandle = new FileStream(rootDirectory + @ "\Test.dat", FileMode.Open, FileAccess.Read);

            start_time = DateTime.Now;
            for (i = 0; i < TOTAL_FILE_SIZE / BUFFER_SIZE; i++)
            {
                FileHandle.Read(buffer, 0, buffer.Length);
            }
            end_time = DateTime.Now;
            ts = end_time - start_time;

            Debug.Print("Read Speed >>>");
            Debug.Print("Total time: " + ts.ToString());
            Debug.Print("Total time in seconds: " + ((float)ts.Ticks / TimeSpan.TicksPerSecond).ToString() + " seconds");
            Debug.Print("Speed: " + (((float)1024) / ((float)ts.Ticks / TimeSpan.TicksPerSecond)).ToString() + " KBytes/s");

            FileHandle.Close();

            ps.UnmountFileSystem();
            ps.Dispose();

            Thread.Sleep(Timeout.Infinite);
        }
    }
}
  • These are some of the results on USBizi (FEZ Mini, Domino, Panda, Rhino). The test was done on firmware version 4.1.3.6 (Beta as of now).

SD SanDisk 1 GB
Write Speed >>>
Total time: 00:00:04.3435675
Total time in seconds: 4.34356737 seconds
Speed: 235.750916 KBytes/s
Testing read…
Read Speed >>>
Total time: 00:00:03.1917835
Total time in seconds: 3.19178367 seconds
Speed: 320.823761 KBytes/s

USB 4GB Kingston DataTraveler
Testing write…
Write Speed >>>
Total time: 00:00:04.8499023
Total time in seconds: 4.84990263 seconds
Speed: 211.13826 KBytes/s
Testing read…
Read Speed >>>
Total time: 00:00:01.8289099
Total time in seconds: 1.82890999 seconds
Speed: 559.896362 KBytes/s

USB SanDisk cruzer micro 256 MB
Write Speed >>>
Total time: 00:00:04.3517377
Total time in seconds: 4.3517375 seconds
Speed: 235.308304 KBytes/s
Testing read…
Read Speed >>>
Total time: 00:00:02.5650228
Total time in seconds: 2.56502271 seconds
Speed: 399.216736 KBytes/s