• <bdo id='EiRja'></bdo><ul id='EiRja'></ul>
  • <legend id='EiRja'><style id='EiRja'><dir id='EiRja'><q id='EiRja'></q></dir></style></legend>

    1. <i id='EiRja'><tr id='EiRja'><dt id='EiRja'><q id='EiRja'><span id='EiRja'><b id='EiRja'><form id='EiRja'><ins id='EiRja'></ins><ul id='EiRja'></ul><sub id='EiRja'></sub></form><legend id='EiRja'></legend><bdo id='EiRja'><pre id='EiRja'><center id='EiRja'></center></pre></bdo></b><th id='EiRja'></th></span></q></dt></tr></i><div id='EiRja'><tfoot id='EiRja'></tfoot><dl id='EiRja'><fieldset id='EiRja'></fieldset></dl></div>
      <tfoot id='EiRja'></tfoot>

      1. <small id='EiRja'></small><noframes id='EiRja'>

        Python tarfile 比 Linux 命令慢

        时间:2023-09-14
        1. <small id='dY5VY'></small><noframes id='dY5VY'>

          • <bdo id='dY5VY'></bdo><ul id='dY5VY'></ul>
            <i id='dY5VY'><tr id='dY5VY'><dt id='dY5VY'><q id='dY5VY'><span id='dY5VY'><b id='dY5VY'><form id='dY5VY'><ins id='dY5VY'></ins><ul id='dY5VY'></ul><sub id='dY5VY'></sub></form><legend id='dY5VY'></legend><bdo id='dY5VY'><pre id='dY5VY'><center id='dY5VY'></center></pre></bdo></b><th id='dY5VY'></th></span></q></dt></tr></i><div id='dY5VY'><tfoot id='dY5VY'></tfoot><dl id='dY5VY'><fieldset id='dY5VY'></fieldset></dl></div>
            <legend id='dY5VY'><style id='dY5VY'><dir id='dY5VY'><q id='dY5VY'></q></dir></style></legend>
                  <tbody id='dY5VY'></tbody>

                <tfoot id='dY5VY'></tfoot>

                  本文介绍了Python tarfile 比 Linux 命令慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试了不同的方式来压缩文件夹.我的理解是 Python 内置模块总是比 subprocess.call("Linux command") 快.但我只是做了一些演示.tarfile 模块比 subprocess.call("tar") 慢.有人可以向我解释一下吗?

                  I tried the different way to zip folder.My understanding is that Python built-in module always faster than subprocess.call("Linux command"). But I just did some demo. The tarfile module is slow than subprocess.call("tar").Can someone explain it to me?

                      #!/usr/bin/python
                  
                  import os
                  import time
                  import tarfile
                  import subprocess
                  
                  tStart1 = time.time()
                  
                  TestFolder = ["Jack", "Robin"]
                  for folder in TestFolder:
                      name = "/mnt/ShareDrive/Share/ExistingUsers/"+folder
                      path = "/mnt/TEST2/"
                      tar = tarfile.open(path+folder+".tar.gz", "w:gz")
                      tar.add(name)
                      tar.close()
                  tEnd1 = time.time()
                  
                  time.sleep(2)
                  
                  tStart2 = time.time()
                  for folder in TestFolder:
                      path = "/mnt/TEST1/"
                      subprocess.call(["tar", "zcvf", path+folder+".tar.gz", "-P", "/mnt/ShareDrive/Share/ExistingUsers/"+folder])
                  tEnd2 = time.time()
                  
                  print "The module cost %f sec" % (tEnd1 - tStart1)
                  print "The subprocess cost %f sec" % (tEnd2 - tStart2)
                  

                  tarfile 模块耗时 63 秒.子流程仅需 32 秒.

                  The tarfile module cost 63 sec. The subprocess cost only 32 sec.

                  两个文件夹的总大小为 433 MB

                  The total size of two folders is 433 MB

                  推荐答案

                  tar 是用 C 语言编写的.tarfile 模块是 tar 处理的纯 Python 实现.模块不可能比命令快.

                  tar is written in C. The tarfile module is a pure Python implementation of tar handling. There is no way that the module will be faster than the command.

                  这篇关于Python tarfile 比 Linux 命令慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:CentOS 5.2 上的 Python 2.6 中缺少 HTTPSConnection 模块 下一篇:检查是否安装了包的 Pythonic 方法

                  相关文章

                  最新文章

                1. <tfoot id='qXkfm'></tfoot>

                      <small id='qXkfm'></small><noframes id='qXkfm'>

                      <i id='qXkfm'><tr id='qXkfm'><dt id='qXkfm'><q id='qXkfm'><span id='qXkfm'><b id='qXkfm'><form id='qXkfm'><ins id='qXkfm'></ins><ul id='qXkfm'></ul><sub id='qXkfm'></sub></form><legend id='qXkfm'></legend><bdo id='qXkfm'><pre id='qXkfm'><center id='qXkfm'></center></pre></bdo></b><th id='qXkfm'></th></span></q></dt></tr></i><div id='qXkfm'><tfoot id='qXkfm'></tfoot><dl id='qXkfm'><fieldset id='qXkfm'></fieldset></dl></div>
                      • <bdo id='qXkfm'></bdo><ul id='qXkfm'></ul>
                      <legend id='qXkfm'><style id='qXkfm'><dir id='qXkfm'><q id='qXkfm'></q></dir></style></legend>