创建/保存 100 个图像到硬盘与 USB 闪存驱动器是测试写入速度的公平测试吗?
我正在编写一些代码来创建位图,进行一些绘图,然后保存到文件。下面是一个简化版本:
FinalImage = new System.Drawing.Bitmap(FinalImageWidth, FinalImageHeight);
Pencil = Graphics.FromImage(FinalImage);
Pencil.Clear(Color.White);
Pencil.DrawImage(image,x,y);
FinalImage.Save(FinalImageSaveLocation + "test" + Counter + ".bmp");
这很好。
出于兴趣,我对这个创建过程进行了超过 100 次写入 C:\ 的计时,结果只用了 2 秒,然后我插入 USB 笔驱动器并向其中写入 100 个图像,花费了 5.5 秒。
我认为闪存驱动器速度更快,尽管我知道不同的笔式驱动器具有不同的功能,并且猜测需要考虑板载 USB 控制器和缓存。我错过了什么吗?
谢谢
I am writing some code to create a Bitmap, do some drawing and then saving to file. Below is a simplified version:
FinalImage = new System.Drawing.Bitmap(FinalImageWidth, FinalImageHeight);
Pencil = Graphics.FromImage(FinalImage);
Pencil.Clear(Color.White);
Pencil.DrawImage(image,x,y);
FinalImage.Save(FinalImageSaveLocation + "test" + Counter + ".bmp");
This is fine.
Out of interest I timed this creation process over 100 times writing to C:\ and it came up as 2secs, I then plugged in a USB Pen drive and wrote 100 image to that and it took 5.5secs.
I thought flash drives were faster although I know different pen drives have different capabilities and guess there is on-board USB controllers and Cache to take into account. Am I missing something?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为两个文件系统之间的相对测试,这应该没问题。至于为什么 USB 驱动器看起来速度较慢,可能有多种原因。也许该特定驱动器使用速度较慢的闪存。也许 USB 接口仅以 12 Mbps(“全速”)运行,而不是 USB 2.0 速度。也许操作系统正在为 HDD 使用内存中回写缓存,这会阻止您查看磁盘的实际性能。
然而,作为绝对写入速度的基准,您的测试可能不是很准确。在内存中创建和绘制位图图像是一项 CPU 和内存密集型任务,因此您的绝对性能值可能会因处理器和内存子系统的性能(或缺乏性能)而产生偏差,从而导致跨多个平台的结果不一致。稍微好一点的方法可能是将 1 KB 内存块清零,在要测试的设备上打开一个随机文件,然后计算将 1 KB 块写入该设备 10,000 次所需的时间。
As a relative test between two filesystems, that should be fine. As for why the USB drive appears to be slower there could be a number of reasons. Perhaps that particular drive uses slower flash memory. Perhaps the USB interface is only running at 12 Mbps ("Full Speed") instead of at USB 2.0 speeds. Perhaps the OS is using an in-memory write-back cache for the HDD that is preventing you from seeing the actual performance of the disk.
As a benchmark of absolute write speed, however, your test may not be very accurate. Creating and drawing a bitmapped image in memory is a CPU and memory-intensive task, and so your absolute performance values may be skewed by the performance (or lack thereof) of the processor and memory subsystems, causing inconsistent results across multiple platforms. A slightly better approach might be to zero-out a 1 KB block of memory, open a random file on the device you want to test, and then time how long it takes to write your 1 KB block 10,000 times to that device.
就向这些设备写入数据的速度而言,该比较是有效的。然而,差异可能是由于硬件差异造成的。 USB 总线可能不如连接硬盘驱动器的总线快,这会减慢速度。另外,如果你的笔已满,而你的硬盘没有满,那么就会产生影响,因为文件会碎片化。
因此,它们可能反映了将文件从计算机保存到其中所需的时间。但它们不能用作磁盘性能的绝对测试。
缓存(正如其他人所说)也很重要。
The comparison is valid in terms of the speed of writing data to these devices. However the differences are likely to be because of the hardware variations. The USB bus may not be as quick as the bus to the hard drive, which will slow it down. Also if you pen was filling up and you hard drive wasn't that would make a difference as the file would be fragmented.
So they probably reflect the time it would take to save files form your computer onto them. But they cannot be used as an absolute test of disk performance.
Caching ( as someone else said ) is also significant.