473,796 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(FileIn fo localFile, string destinationPath )
{
// Collect the time when we start
DateTime Start = DateTime.Now;

// Copy the file, with overwrite
localFile.CopyT o(destinationPa th, true);

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

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

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

--
lucas

Feb 12 '07 #1
9 6228
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(FileIn fo localFile, string destinationPath )
{
// Collect the time when we start
DateTime Start = DateTime.Now;

// Copy the file, with overwrite
localFile.CopyT o(destinationPa th, true);

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

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

// 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.goog legroups.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.goo glegroups.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 "FlushFileBuffe rs" 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 FlushFileBuffer s when done.

Willy.

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

[DllImport("kern el32", SetLastError = true)]
static extern void FlushFileBuffer s(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.comw rote:
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.comw rote in message
news:11******** **************@ v45g2000cwv.goo glegroups.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
7444
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 complicated. I know it is possiable to do this in PHP but I can't think of how. All I need to figure out is if they are on dial up or not. It doesn't have to be 100% accurate but at least 50% accurate. Any help is greatly appreciated.
1
1735
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 library. Marquee text was RUNNING to another galaxy.. I assume that this kind of script is difficult to make 100% good, but maybe with browser sniffing and some javascript speed testing more or less working script could be achieved?
4
2083
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
7511
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 testing the code and added in some exception handling to cater for any problems. During testing I have found that if I attempt to save to a floppy disc that is full, a System.IO.IOException is raied with the message "There is not enough space on the...
11
9220
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. ------------------------------------------------------------ -- Test schema create table logs ( logid serial primary key, ctime integer not null,
5
2179
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 nutshell description of the test. The testing was done at "DB2/LINUX 8.2.3". Tables for tests: F4106 has 5203 rows, 32 columns. F42199 has 1399252 rows, 245 columns.
34
29905
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
188
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 segregated data prep into a separate process to avoid excessive memory use at run time. Turns out python For the site I'm at, I've got 10 years sales history recapped from
2
2093
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 some sample source code to optimize system performance. Thanks pavani
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10003
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.