c# - Calculating hard drive throughput -


my app creates 2gb file , needs select fastest drive on system enough space. trying calculate throughput creating file, setting length, writing data sequentially follows:

fileinfo file = null; var drives = driveinfo.getdrives(); var stats = new list<driveinfostatistics>();  foreach (var drive in drives) {         {         file = new fileinfo(path.combine(drive.rootdirectory.fullname, guid.newguid().tostring("d") + ".tmp"));     }     while (file.exists);      try     {         using (var stream = file.open(filemode.createnew, fileaccess.write, fileshare.none))         {             var seconds = 10;             var framerate = 120f;             var byteswritten = 0l;             var bytesperpixel = 1;             var watch = new stopwatch();             var videosize = new size(1328, 1048);             var buffer = new byte [(int) (videosize.width * videosize.height * bytesperpixel)];              stream.setlength((long) (videosize.width * videosize.height * bytesperpixel * framerate * seconds));              watch.restart();             (int = 0; < seconds; i++)             {                 (int j = 0; j < framerate; j++)                 {                     stream.write(buffer, 0, buffer.length);                     byteswritten += buffer.length;                 }             }             watch.stop();              stats.add(new driveinfostatistics(drive, byteswritten / watch.elapsed.totalseconds));         }     }     catch     {     }         {         file.refresh();         if (file.exists) { try { file.delete(); } { file.refresh(); } }     } }  if (stats.count == 0) {     throw (new exception("no suitable drives found.")); } else {     stats.sort((x, y) => y.datatransferrate.compareto(x.datatransferrate));      message         = "the following drives suitable candidates (best worst):"         + environment.newline         + environment.newline         + string.join(environment.newline, stats.convertall<string>(s => (s.driveinfo.rootdirectory.fullname.substring(0, 2).toupper() + " " + conversionutilities.toisubytesnotation(s.datatransferrate) + "ps")))         + environment.newline         + environment.newline         + "test results may vary based on other applications accessing drives."         + environment.newline         + environment.newline         + "try test system configured in production."         ;      messagebox.show(message); } 

the results getting make no sense:

desktop

d: 4.15 gbps // ssd. f: 4.09 gbps // hdd (5200 rpm). e: 4.06 gbps // hdd (7500 rpm). c: 4.03 gbps // ssd. h: 2.45 gbps // ram disk!!! 
  • first of all, ssds , hdds close together.
  • secondly, speeds faster expect.
  • thirdly, ram disk (created ramdisk) seems have lowest throughput. in practice, ram disk outperforms others far when writing actual video data.

laptop

e: 981.24 mbps // ram disk. c: 100.17 mbps // hdd (5200 rpm). d: 055.94 mbps // hdd (5200 rpm). 

the results of same code on development laptop more believable.

is there wrong code above? if not, how explain throughput of 4 gbps ssd while ram disk tops out @ 2.5 gbps?

i understand there many factors affecting throughput , benchmarking software sophisticated. however, in case writing 2gb video file @ 120 frames per second without losing frames crucial , above code supposed present user quick , dirty recommendation on drive use hold transient video frames. frames later post-processed , transcoded mp4 video few megabytes in size.

lastly, have tried above code alongside contig.exe sysinternals ensure contiguous layout better hdd performance. however, did not notice difference in performance indicates file not fragmented enough begin (upon creation).

if program writes data disk, there happen quite lot of different things:

first data written ram buffer , operation acknowledged writing program way before data transfered next stages.

then data written harddisk controller may own caching.

then data written hard-drive in turn may own caching.

it complicated measure real throughput high level software.

one possibility: write large file, expected larger chaches in operating system / controler/hard drive. gives estimate of sustained writing rate.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -