File.Copy Speed

Junkee

Member
Joined
May 7, 2006
Messages
7
Location
England
Hi,

Ive written a little app which reads Winamp .m3u playlist files and copies all of the songs in there to a directory of the users choice. Useful for making MP3 CDs for the car.

Everything works fine, no problems. Im just concerned about the speed, especially the fact that running in debug mode within VS is faster than running the release mode .exe.

This is the function that I use to copy the files.
I should mention that the variable Dir is a string which contains the directory the user wants to copy the files to. Oh, and each item in the listbox lstTracks is a full path to an mp3, so each item is something along the lines of D:\Artist\Album\Song.mp3

C#:
        private void CopyFiles()
        {
            // Set up progress bar
            progressBar.Minimum = 0;
            progressBar.Maximum = lstTracks.Items.Count;
            progressBar.Step = 1;

            string[] songNameArray;
            string songName;
            // Copy the files in the playlist to Dir\
            foreach (object mp3 in lstTracks.Items)
            {
                lblCurrentTrack.Text = String.Format("Copying track {0} of {1}", lstTracks.Items.IndexOf(mp3), lstTracks.Items.Count.ToString());
                lblCurrentTrackName.Text = mp3.ToString();
                
                songNameArray = mp3.ToString().Split(\\);
                songName = songNameArray[songNameArray.Length-1];

                if (File.Exists(mp3.ToString()))
                    File.Copy(mp3.ToString(), Dir + @"\" + songName, true);
                else
                    errorLog += "|Could not copy: " + mp3.ToString();

                progressBar.PerformStep();
                Application.DoEvents();
            }

            if (errorLog.Length > 31)
            {
                string[] errors = errorLog.Split(|);
                MessageBox.Show("Some song(s) could not be copied. Please see\n"
                                 + Dir + "\\error.log\nfor details.");
                File.WriteAllLines(Dir + "\\error.log", errors);
            }
            else { MessageBox.Show(lstTracks.Items.Count.ToString() + 
                            " copied sucesfully."); }
            
        }

Is there any reason why the same operation (copying the exact same playlist to the exact same location) takes longer in release mode than in debug mode?

Any help would be appreciated, thanks :D
 
Hi,

Ive just copied a playlist of 193 songs totalling 965MB. In debug mode from the VS IDE it took 64 seconds. In from the release exe it took 89 seconds to do the exact same operation (same playlist, copying to the same drive and directory, same processes in the background etc).

It isnt exactly a problem for me to wait 1 minute and a half for something, I just find it odd that theres such a difference. I just wanted to improve it where possible.

Thanks,
 
Since the operation is so large, I dont think that JIT compiling, assembly caching, or anything like that is going to have signifigant impact on performance, hence the order is not particularly relevant, but to be sure, you really ought to try each method a few times and mix up the order.
 
The reason I asked what order the test were performed was incase the files had been cached in a page file and as such the hdd was able to access them quicker.
 
Back
Top