Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copyfile really slow

272 views
Skip to first unread message

Anders Berthelsen

unread,
Sep 5, 2010, 10:02:05 AM9/5/10
to
I have a list of files i would like to make matlab copy from one folder to another. I make a loop over the files, and use copyfile on each file. For 200 files matlab takes 5-6 minutes, whereas windows take about a second. The files are small text files.

I need not to copy all the files in the folder, so i just can't copy the whole folder.

Any solutions?

Walter Roberson

unread,
Sep 5, 2010, 12:48:55 PM9/5/10
to

Consider constructing command line strings and using system() on them.

I have seen a couple of other postings indicating that copyfile was very
slow for some people. Which version of Matlab, and which MS Windows are
you using? And is this to a hard disk or a networked file system?

I looked at the documentation for copyfile and found that on Unix-type
systems it was necessarily slower than using the system routines,
because it has some differences in defined operation than the Unix
routines do (having to do with permissions, and having to do with what
the result is to be if you are copying to a destination name that
already exists but the copying does not work for some reason.)

Jan Simon

unread,
Sep 6, 2010, 5:20:20 AM9/6/10
to
Dear Anders,

COPYFILE was surprisingly slow in Matlab 6.5, because it used two DOS calls:
1. dos('ver') and a following time-consuming parsing to identify the capabilities of the OS.
2. dos('copy ...') for the actual copy.
It was easy to create a copy, which performs the OS identification once only and store it in a PERSISTENT variable. ==> 8 times faster!

Fortunately Matlab 7.? uses a compiled built-in function, which is about 20 times faster than the old DOS stuff.
I've created a compiled C-mex function, which is 25% faster under Matlab 7, if the files have not been read before (not in the hard-disk cache), and 75% faster if the files are in the cache already. But this function is simpler than Matlab's COPYFILE: No 'forced' writing, no wildcards.

My conclusion: If you are using Matlab 7, a slow copy is not caused by COPYFILE, but by a slow network connection or a sensitive Virus checker.

Kind regards, Jan

0 new messages