Skip to content

Instantly share code, notes, and snippets.

@baszoetekouw
Created September 16, 2017 16:12
Show Gist options
  • Save baszoetekouw/9374fd20512a526430fd4b4282e50857 to your computer and use it in GitHub Desktop.
Save baszoetekouw/9374fd20512a526430fd4b4282e50857 to your computer and use it in GitHub Desktop.
#!python3
import datetime
import shutil
import os
import subprocess
# source and destiantion trees
src="/data/Backup/src/test-copy/src"
dst1="/data/Backup/src/test-copy/dst1"
dst2="/data/Backup/src/test-copy/dst2"
dst3="/data/Backup/src/test-copy/dst3"
# remove old dirs
print("Clean up");
for d in (dst1,dst2,dst3):
if os.path.isdir(d): subprocess.run(["/bin/rm","-rf",d])
# make sure everything is cached
print("Cache run")
subprocess.run(["/bin/cp","-al", src, dst1])
# now let's compare copytree to gnu cp
print("Python copytree run")
start1 = datetime.datetime.now()
shutil.copytree(src, dst2, copy_function=os.link)
stop1 = datetime.datetime.now()
print("GNU cp run")
start2 = datetime.datetime.now()
subprocess.run(["/bin/cp","-al", src, dst3])
stop2 = datetime.datetime.now()
print("Result:")
print("Python: {:.3f}s".format((stop1-start1)/datetime.timedelta(seconds=1)))
print("GNU cp: {:.3f}s".format((stop2-start2)/datetime.timedelta(seconds=1)))
print("diff : (:.3f}s".format((stop1-start1-stop2+start2)/datetime.timedelta(seconds=1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment