Discussion:
Speed of shutil.copy vs os.system("copy src dest") in win32
Tim Golden
2006-04-27 07:41:34 UTC
Permalink
[Russell Warren]

| I just did a comparison of the copying speed of shutil.copy
| against the
| speed of a direct windows copy using os.system. I copied a file that
| was 1083 KB.
|
| I'm very interested to see that the shutil.copy copyfileobj
| implementation of hacking through the file and writing a new one is
| significantly faster... any clue as to why this is? I figure I'm
| missing something here.

There are a couple of other options as well which
may or may not be faster. I'd meant to time things
before putting this page up but never got round to
it; maybe I'll give it another go:

http://tgolden.sc.sabren.com/python/win32_how_do_i/copy-a-file.html

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
Russell Warren
2006-04-26 18:07:23 UTC
Permalink
I just did a comparison of the copying speed of shutil.copy against the
speed of a direct windows copy using os.system. I copied a file that
was 1083 KB.

I'm very interested to see that the shutil.copy copyfileobj
implementation of hacking through the file and writing a new one is
significantly faster... any clue as to why this is? I figure I'm
missing something here.

Does os.system launch a cmd shell every time?
import timeit
timeit.Timer(stmt= r'shutil.copy(r"c:\windows\ntbtlog.txt", r"c:\temp")',setup="import shutil").repeat(repeat=5,number=100)
[0.99285104671434965, 0.68337121058721095, 0.84528340892575216,
0.87780765432398766, 0.8709894693311071]
timeit.Timer(stmt= r'os.system(r"copy c:\windows\ntbtlog.txt c:\temp")',setup="import os").repeat(repeat=5,number=100)
[2.8546278926514788, 2.3763950446300441, 2.4444609580241377,
2.4392499605455669, 2.4446956247265916]
Tim Roberts
2006-04-27 07:17:53 UTC
Permalink
Post by Russell Warren
I just did a comparison of the copying speed of shutil.copy against the
speed of a direct windows copy using os.system. I copied a file that
was 1083 KB.
I'm very interested to see that the shutil.copy copyfileobj
implementation of hacking through the file and writing a new one is
significantly faster... any clue as to why this is? I figure I'm
missing something here.
Does os.system launch a cmd shell every time?
Yes. That's in the documentation.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
Loading...