Speed of shutil.copy vs os.system("copy src dest") in win32

Discussion in 'Python' started by Russell Warren, Apr 26, 2006.

  1. 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]
     
    Russell Warren, Apr 26, 2006
    #1
    1. Advertising

  2. Russell Warren

    Tim Roberts Guest

    "Russell Warren" <> wrote:

    >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,
    Providenza & Boekelheide, Inc.
     
    Tim Roberts, Apr 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bmgz
    Replies:
    1
    Views:
    1,145
    Hans Nowak
    Dec 16, 2003
  2. Joe

    file copy shutil

    Joe, Feb 9, 2004, in forum: Python
    Replies:
    1
    Views:
    353
    Michael Hudson
    Feb 9, 2004
  3. Tim Golden
    Replies:
    0
    Views:
    627
    Tim Golden
    Apr 27, 2006
  4. dave
    Replies:
    6
    Views:
    1,099
  5. Fletcher Johnson

    Why is the shutil module called shutil?

    Fletcher Johnson, Sep 24, 2011, in forum: Python
    Replies:
    11
    Views:
    912
    alex23
    Sep 26, 2011
Loading...

Share This Page