Created
June 4, 2012 15:55
-
-
Save chenshuo/2869173 to your computer and use it in GitHub Desktop.
trivial file download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| import socket, os, hashlib, time | |
| md5 = hashlib.md5() | |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| sock.connect(('server_address', 2021)) | |
| start = time.time() | |
| length = 0 | |
| out = open('/tmp/download', 'wb') | |
| while True: | |
| message = sock.recv(65536) | |
| if message: | |
| length += len(message) | |
| md5.update(message) | |
| out.write(message) | |
| else: | |
| print "done" | |
| sock.close() | |
| out.close() | |
| break | |
| seconds = time.time() - start | |
| print md5.hexdigest() | |
| print length, " bytes" | |
| print "%.3f seconds" % (seconds) | |
| print "%.3f MiB/s" % (length/seconds/1024/1024) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ time ./download.py | |
| done | |
| 7c148e0a1b330186adef66ee3e2d433d | |
| 4238800896 bytes | |
| 36.339 seconds | |
| 111.243 MiB/s | |
| real 0m36.357s | |
| user 0m13.490s | |
| sys 0m14.390s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment