From ec21971a10ec673f8a4257c3dacac639f175939e Mon Sep 17 00:00:00 2001 From: McBochi Date: Wed, 25 Jun 2014 18:26:14 +0200 Subject: [PATCH] Fixes sivel/speedtest-cli#76 --- speedtest_cli.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/speedtest_cli.py b/speedtest_cli.py index b794681..7540b6f 100755 --- a/speedtest_cli.py +++ b/speedtest_cli.py @@ -22,7 +22,7 @@ source = None shutdown_event = None import math -import time +import timeit import os import sys import threading @@ -177,7 +177,7 @@ class FileGetter(threading.Thread): def run(self): self.result = [0] try: - if (time.time() - self.starttime) <= 10: + if (timeit.default_timer() - self.starttime) <= 10: f = urlopen(self.url) while 1 and not shutdown_event.isSet(): self.result.append(len(f.read(10240))) @@ -191,7 +191,7 @@ class FileGetter(threading.Thread): def downloadSpeed(files, quiet=False): """Function to launch FileGetter threads and calculate download speeds""" - start = time.time() + start = timeit.default_timer() def producer(q, files): for file in files: @@ -215,14 +215,14 @@ def downloadSpeed(files, quiet=False): q = Queue(6) prod_thread = threading.Thread(target=producer, args=(q, files)) cons_thread = threading.Thread(target=consumer, args=(q, len(files))) - start = time.time() + start = timeit.default_timer() prod_thread.start() cons_thread.start() while prod_thread.isAlive(): prod_thread.join(timeout=0.1) while cons_thread.isAlive(): cons_thread.join(timeout=0.1) - return (sum(finished) / (time.time() - start)) + return (sum(finished) / (timeit.default_timer() - start)) class FilePutter(threading.Thread): @@ -240,7 +240,7 @@ class FilePutter(threading.Thread): def run(self): try: - if ((time.time() - self.starttime) <= 10 and + if ((timeit.default_timer() - self.starttime) <= 10 and not shutdown_event.isSet()): f = urlopen(self.url, self.data) f.read(11) @@ -255,7 +255,7 @@ class FilePutter(threading.Thread): def uploadSpeed(url, sizes, quiet=False): """Function to launch FilePutter threads and calculate upload speeds""" - start = time.time() + start = timeit.default_timer() def producer(q, sizes): for size in sizes: @@ -279,14 +279,14 @@ def uploadSpeed(url, sizes, quiet=False): q = Queue(6) prod_thread = threading.Thread(target=producer, args=(q, sizes)) cons_thread = threading.Thread(target=consumer, args=(q, len(sizes))) - start = time.time() + start = timeit.default_timer() prod_thread.start() cons_thread.start() while prod_thread.isAlive(): prod_thread.join(timeout=0.1) while cons_thread.isAlive(): cons_thread.join(timeout=0.1) - return (sum(finished) / (time.time() - start)) + return (sum(finished) / (timeit.default_timer() - start)) def getAttributesByTagName(dom, tagName): @@ -400,10 +400,10 @@ def getBestServer(servers): h = HTTPSConnection(urlparts[1]) else: h = HTTPConnection(urlparts[1]) - start = time.time() + start = timeit.default_timer() h.request("GET", urlparts[2]) r = h.getresponse() - total = (time.time() - start) + total = (timeit.default_timer() - start) except (HTTPError, URLError): cum.append(3600) continue