Skip to content

Instantly share code, notes, and snippets.

@CedricCabessa
Last active June 10, 2016 13:53
Show Gist options
  • Save CedricCabessa/8d87c9e94c5b6ac59aaf6b5c8248285d to your computer and use it in GitHub Desktop.
Save CedricCabessa/8d87c9e94c5b6ac59aaf6b5c8248285d to your computer and use it in GitHub Desktop.
adbbench.py
#!/usr/bin/env python3
# ./adbtest.py ~/Downloads/1GB.zip
import sys, subprocess, os, time, tempfile, hashlib, shutil
#ADB = os.path.expanduser("~/genymotion/tools/adb")
ADB = "adb"
payload = sys.argv[1]
payload_file = os.path.basename(payload)
timestamp_before = time.perf_counter()
subprocess.check_call([ADB, "push", payload, "/sdcard/Download"], stderr=subprocess.DEVNULL)
timestamp_after = time.perf_counter()
print("Time elapsed for push %f" % (timestamp_after - timestamp_before))
tmpout = tempfile.mkdtemp()
timestamp_before = time.perf_counter()
subprocess.check_call([ADB, "pull", "/sdcard/Download/" + payload_file, tmpout],
stderr=subprocess.DEVNULL)
timestamp_after = time.perf_counter()
print("Time elapsed for pull %f" % (timestamp_after - timestamp_before))
m = hashlib.sha1()
m.update(open(payload, 'rb').read())
digest_src = m.digest()
m = hashlib.sha1()
m.update(open(tmpout + os.sep + payload_file, 'rb').read())
digest_push = m.digest()
assert(digest_src == digest_push)
shutil.rmtree(tmpout)
@thomascarpentier
Copy link

Merci Ced, on peut faie la meme chose pour windows ?

@agateau-g
Copy link

ça doit marcher pour Windows, si tu ajoutes adb dans PATH. ll faut peut être juste remplacer adb par adb.exe ligne 8 (voire par le chemin complet, comme ça tu t'embêtes pas à l'ajouter dans le PATH)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment