Vista and External Memory Devices
Update - read the first two comments. I'm leaving the rest of the article as it is in order to avoid revisionism. The solution is in the first two comments though.
According to the Windows Vista feature page, Vista is going to be able to use external memory devices (USB flash drives and the like to you and me) to act as extra memory to save having to go to the hard disk. I've heard this mentioned at a few places, and it's always asserted that EMDs are slower than memory but "much, much faster" than disks. This has just been stated as a fact that everyone would just go along with. I've been a bit skeptical myself, so I thought I'd write a couple of very simple benchmarks. I emphasise the fact that they're very simple because it could well be that I'm missing something very important.
Here are three classes. Writer just writes out however many blocks of 1MB data you ask it to, to whichever file you ask it to. Reader simply reads a whole file in 1MB chunks. RandomReader reads however many 1MB chunks you ask it to, seeking randomly within the file between each read.
Writer
using System;
using System.IO;
public class Writer
{
static void Main(string[] args)
{
Random rng = new Random();
byte[] buffer = new byte[1024*1024];
DateTime start = DateTime.Now;
using (FileStream stream = new FileStream (args[0], FileMode.Create))
{
for (int i=0; i < int.Parse(args[1]); i++)
{
rng.NextBytes(buffer);
Console.Write(".");
stream.Write(buffer, 0, buffer.Length);
}
}
DateTime end = DateTime.Now;
Console.WriteLine();
Console.WriteLine (end-start);
}
}
|
Reader
using System;
using System.IO;
public class Reader
{
static void Main(string[] args)
{
byte[] buffer = new byte[1024*1024];
DateTime start = DateTime.Now;
int total=0;
using (FileStream stream = new FileStream (args[0], FileMode.Open))
{
int read;
while ( (read=stream.Read (buffer, 0, buffer.Length)) > 0)
{
total += read;
Console.Write(".");
}
}
DateTime end = DateTime.Now;
Console.WriteLine();
Console.WriteLine (end-start);
Console.WriteLine (total);
}
}
|
RandomReader
using System;
using System.IO;
public class RandomReader
{
static void Main(string[] args)
{
byte[] buffer = new byte[1024*1024];
Random rng = new Random();
DateTime start = DateTime.Now;
int total=0;
using (FileStream stream = new FileStream (args[0], FileMode.Open))
{
int length = (int) stream.Length;
for (int i=0; i < int.Parse(args[1]); i++)
{
stream.Position = rng.Next(length-buffer.Length);
total += stream.Read (buffer, 0, buffer.Length);
Console.Write(".");
}
}
DateTime end = DateTime.Now;
Console.WriteLine();
Console.WriteLine (end-start);
Console.WriteLine (total);
}
}
|
I have five devices I can test: a 128MB Creative Muvo (USB), a 1GB PNY USB flash drive, a Viking 512MB SD card, my laptop hard disk (fairly standard 60GB Hitachi drive) and a LaCie 150GB USB hard disk. (All USB devices are USB 2.0.) The results are below. This is pretty rough and ready - I was more interested in the orders of magnitude than exact figures, hence the low precision given. All figures are in MB/s.
| Drive | Write | Stream read | Random read |
| Internal HDD |
17.8 |
24 |
22 |
| External HDD |
14 |
20 |
22 |
| SD card |
2.3 |
7 |
8.3 |
| 1GB USB stick |
3.3 |
10 |
10 |
| 128MB USB stick |
1.9 |
2.9 |
3.5 |
Where possible, I tried to reduce the effects of caching by mixing the tests up, so I never ran two tests on the same location in succession. Some of the random reads will almost certainly have overlapped each other within a test, which I assume is the reason for some of the tests showing faster seek+read than streaming reads.
So, what's wrong with this picture? Why does MS claim that flash memory is much faster than hard disks, when my flash drives appear to be much slower than my laptop and external drives? (Note that laptop disks aren't noted for their speed, and I don't have a particularly fancy one.) It doesn't appear to be the USB bus - the external hard disk is fine. The 1GB stick and the SD card are both pretty new, although admittedly cheap. I doubt that either of them are worse quality than the majority of flash drives in the hands of the general public now, and I don't expect the average speed to radically increase between now and the Vista launch, in terms of what people actually own.
I know my tests don't accurately mimic how data will be accessed by Vista - but how is it so far out? I don't believe MS would have invested what must have been a substantial amount of resource into this feature without conducting rather more accurate benchmarks than my crude ones. I'm sure I'm missing something big, but what is it? And if flash can genuinely work so much faster than hard disks, why do flash cards perform so badly in simple file copying etc?