473,395 Members | 1,462 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

USB Disk speed testing in C#

Hi all,

I am attempting to write a tool that would get (via something of a
stopwatch action) the amount of time it takes to copy a file from a
local disk to a connected USB drive on a Windows XP machine.

When I run this tool, I am getting average speeds that are faster than
what is theoretically possible over a full-speed USB connection (the
disk is enumerated at Full speed, not High Speed).

When I simply drag and drop a file, using the computer clock to
crudely time the transfer, the copy process takes much longer than
what my program would indicate (via returned times), but with times
that are much more realistic than what I am seeing. The files I am
transferring are text files of specific sizes that I generate at
runtime.

So my question, is there some form of asynchronous transferring going
on? Does the CopyTo call in my code below kick out before all the
information in the file is transferred? Are there OS optimizations
that are causing havok? This seems to be the case, so how can I test
for when the file is completely copied over?

I chose to use C# for this, but have been reading on this group that
there are weaknesses in the language when it comes to file
manipulation. Any suggestions for better approaches / language
choices would be appreciated.

Here is a bit of what I am currently doing:

private TimeSpan CopyFile(FileInfo localFile, string destinationPath)
{
// Collect the time when we start
DateTime Start = DateTime.Now;

// Copy the file, with overwrite
localFile.CopyTo(destinationPath, true);

// Collect the time when we finish
DateTime stop = DateTime.Now;

// Find the difference
TimeSpan diff = stop.Subtract(start);

// Return difference
return diff;
}
Thank you in advance for any responses

--
lucas

Feb 12 '07 #1
9 6194
Well your "rough timing" code looks OK. Remember that when you drag-drop a
file using Windows Explorer, there is a lot more going on than just a plain
old copy operation. You are getting estimated times being computed, UI
progress being updated, and so on. Gotta compare apples to apples.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"st******@gmail.com" wrote:
Hi all,

I am attempting to write a tool that would get (via something of a
stopwatch action) the amount of time it takes to copy a file from a
local disk to a connected USB drive on a Windows XP machine.

When I run this tool, I am getting average speeds that are faster than
what is theoretically possible over a full-speed USB connection (the
disk is enumerated at Full speed, not High Speed).

When I simply drag and drop a file, using the computer clock to
crudely time the transfer, the copy process takes much longer than
what my program would indicate (via returned times), but with times
that are much more realistic than what I am seeing. The files I am
transferring are text files of specific sizes that I generate at
runtime.

So my question, is there some form of asynchronous transferring going
on? Does the CopyTo call in my code below kick out before all the
information in the file is transferred? Are there OS optimizations
that are causing havok? This seems to be the case, so how can I test
for when the file is completely copied over?

I chose to use C# for this, but have been reading on this group that
there are weaknesses in the language when it comes to file
manipulation. Any suggestions for better approaches / language
choices would be appreciated.

Here is a bit of what I am currently doing:

private TimeSpan CopyFile(FileInfo localFile, string destinationPath)
{
// Collect the time when we start
DateTime Start = DateTime.Now;

// Copy the file, with overwrite
localFile.CopyTo(destinationPath, true);

// Collect the time when we finish
DateTime stop = DateTime.Now;

// Find the difference
TimeSpan diff = stop.Subtract(start);

// Return difference
return diff;
}
Thank you in advance for any responses

--
lucas

Feb 12 '07 #2
Peter wrote:
Well your "rough timing" code looks OK. Remember that when you drag-drop a
file using Windows Explorer, there is a lot more going on than just a plain
old copy operation. You are getting estimated times being computed, UI
progress being updated, and so on. Gotta compare apples to apples.
Peter

I agree. It still burns that the calculation done from this specific
visual "timer" is much more realistic of a value than the result from
the code calculation.

My current attempt is to manually write the files at the byte level.
I can only assume that this would bypass any undocumented / unknown
features that are causing the issues I am seeing.

--
lucas

Feb 12 '07 #3
On Feb 12, 3:45 pm, sturn...@gmail.com wrote:
I chose to use C# for this, but have been reading on this group that
there are weaknesses in the language when it comes to file
manipulation. Any suggestions for better approaches / language
choices would be appreciated.
Hi,

The language doesn't matter, as you're using the .Net framework. So
VB.Net would be the same. I'm not sure what posts your referring to
that claim there are 'weaknesses' with file manipulation in C#... it
sounds like a very suspicious statement.

Feb 12 '07 #4
<st******@gmail.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
Peter wrote:
>Well your "rough timing" code looks OK. Remember that when you drag-drop a
file using Windows Explorer, there is a lot more going on than just a plain
old copy operation. You are getting estimated times being computed, UI
progress being updated, and so on. Gotta compare apples to apples.
Peter


I agree. It still burns that the calculation done from this specific
visual "timer" is much more realistic of a value than the result from
the code calculation.

My current attempt is to manually write the files at the byte level.
I can only assume that this would bypass any undocumented / unknown
features that are causing the issues I am seeing.

--
lucas

What you are measuring is *not* the time it takes to copy a complete file from disk to disk
physically, you are actually measuring the time needed to copy file data to the FS cache,
your timing stops when the file is completed in the cache but before it's actually written
to disk.
Explorer shows you more accurately what's happening because it uses a callback to show
progress, note that even here, it's possible that the FS cache is not completely written to
disk (callbacks are per 64KB on XP) when explorer tells you it has done, note that in case
of a hard disk, it's possible that the HD buffer is not (completely) physically written to
disk before explorer says it has done with the copy.

Willy.
Feb 12 '07 #5

Willy Denoyette [MVP] wrote:
What you are measuring is *not* the time it takes to copy a complete file from disk to disk
physically, you are actually measuring the time needed to copy file data to the FS cache,
your timing stops when the file is completed in the cache but before it's actually written
to disk.

Thank you Willy, this is extermely helpful. According to filemon
(disk activity moniter), you are absolutely correct.

I suppose that answers my first question, so for a follow-up:

Do you have any suggestions how I can determine the true write time
for copying a file? Would using a Stream object and copying the local
file X bytes at a time to an attached drive give me reasonablly valid
timings? Is there a way to determine when all my information has
exited the FS cache?

--
lucas

Feb 12 '07 #6
<st******@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
>
Willy Denoyette [MVP] wrote:
>What you are measuring is *not* the time it takes to copy a complete file from disk to
disk
physically, you are actually measuring the time needed to copy file data to the FS cache,
your timing stops when the file is completed in the cache but before it's actually
written
to disk.


Thank you Willy, this is extermely helpful. According to filemon
(disk activity moniter), you are absolutely correct.

I suppose that answers my first question, so for a follow-up:

Do you have any suggestions how I can determine the true write time
for copying a file? Would using a Stream object and copying the local
file X bytes at a time to an attached drive give me reasonablly valid
timings? Is there a way to determine when all my information has
exited the FS cache?

--
lucas

It's not that easy to measure this exactly, even Filemon tells you only when data goes to
the FS, not when the IO manager flushes the cache buffers to disk.
What you can do for instance is use a FileStream (one for reading and one for writing), when
done you should have to PInvoke "FlushFileBuffers" to force the FS to flush it's buffers.
Another option is to use large buffers ( guess 64KB, but I'm not entirely sure about this)
to prevent File system buffering when writing to disk, note that even in this case I would
suggest you to call FlushFileBuffers when done.

Willy.

PS here the PInvoke declaration. Pass the output FileStream handle as parameter when done
writing.

[DllImport("kernel32", SetLastError = true)]
static extern void FlushFileBuffers(IntPtr handle);

Feb 12 '07 #7
Could I see full code on how to transfer file via USB.
Thanks

Feb 13 '07 #8
Andy

C# does not support working with files and folders in a fast manner

Windows Script Host works well enough so who gives a fuck about some
new-fangled language?


On Feb 12, 1:14 pm, "Andy" <a...@med-associates.comwrote:
On Feb 12, 3:45 pm, sturn...@gmail.com wrote:
I chose to use C# for this, but have been reading on this group that
there are weaknesses in the language when it comes to file
manipulation. Any suggestions for better approaches / language
choices would be appreciated.

Hi,

The language doesn't matter, as you're using the .Net framework. So
VB.Net would be the same. I'm not sure what posts your referring to
that claim there are 'weaknesses' with file manipulation in C#... it
sounds like a very suspicious statement.

Feb 14 '07 #9
Ignore the susiedba post; he's trolling.
Robin S.
-----------------------------------------
"Andy" <an***@med-associates.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
On Feb 12, 3:45 pm, sturn...@gmail.com wrote:
>I chose to use C# for this, but have been reading on this group that
there are weaknesses in the language when it comes to file
manipulation. Any suggestions for better approaches / language
choices would be appreciated.

Hi,

The language doesn't matter, as you're using the .Net framework. So
VB.Net would be the same. I'm not sure what posts your referring to
that claim there are 'weaknesses' with file manipulation in C#... it
sounds like a very suspicious statement.

Feb 15 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Jordanakins | last post by:
Usenet, I am currently working on my website and am needing to detect the connection speed of the client. I would like to do this in PHP and not use any other languages. This makes it a bit more...
1
by: Perttu Pulkkinen | last post by:
Has someone for leisure's sake develepoded a script that would help to set quite same marquee speed in different environments. Why: because I noticed a VERY big difference in certain Mac's in local...
4
by: Il Prof | last post by:
Hi to everyone! ;) In C language on Linux, what string access method is faster? 1) Puntatori char str="hello"; char* pstr; pstr = str; // access such as "*pstr"
5
by: Karl | last post by:
Hi, I have some code that will save the contents of a Rich Text Box in either a Text or Rich Text Format file. The code is using the SaveFileDialog and is working correctly. I have been...
11
by: Sezai YILMAZ | last post by:
Hello I need high throughput while inserting into PostgreSQL. Because of that I did some PostgreSQL insert performance tests. ------------------------------------------------------------ --...
5
by: Konstantin Andreev | last post by:
Recently I became interested, - Are the data, bulk loaded in the table with LOAD utility, consume the same disk space as loaded with IMPORT utility? The answer turned out to be NOT ! Here is a...
34
by: Tom | last post by:
I'd greatly appreciate advice and code snippets on how to create a ram disk within a C/C++ program. I also need to be able to determine the free space. Thanks in advance for any help.
0
by: Emile van Sebille | last post by:
Laszlo Nagy wrote: Hmm... I wrote an browser based analysis tool and used the working name pyvot... I found Numeric to provide the best balance of memory footprint and speed. I also...
2
by: pavanip | last post by:
Hi, I have an application like Optimize System Performance by using Memory speed, cpu speed and Disk speed. How to optimize memory speed,disk optimization and CPU optimization. Please provide me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.