From 7eef9f28e5ae847ae30fc03f5af9930a6a74b1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Jansons?= Date: Sun, 21 Oct 2012 08:49:13 +0300 Subject: [PATCH] Improved upload test data generation speed mentioned in issue #2. Tweaked download and upload test steps to solve issue #1. --- README | 4 ++-- tespeed.py | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README b/README index c17087a..621171a 100644 --- a/README +++ b/README @@ -45,13 +45,13 @@ What the script does: TODO: - * Add error checking. + * Add more error checking. * Make it less messy. * Send found results to speedtest.net API (needs some hash?) and get the link to the generated image. * Store the measurement data and draw graphs. * Measure the speed for the whole network interface (similar like it was in the old version of Tespeed). - * Random data generator uses too much resources. + diff --git a/tespeed.py b/tespeed.py index 86fd8b3..be9f7ba 100755 --- a/tespeed.py +++ b/tespeed.py @@ -79,10 +79,13 @@ def __init__(self, server = "", numTop = 0): self.latencycount=10 self.bestServers=5 self.numTop=int(numTop) - self.downList=['350x350', '500x500', '750x750', '1000x1000', - '1500x1500', '2000x2000', '2500x2500', '3000x3000', - '3500x3500', '4000x4000'] - self.upSizes=[1024*512, 1024*1024, 1024*1024*2, 1024*1024*4] + self.downList=['350x350', '500x500', '750x750', '1000x1000', + '1500x1500', '2000x2000', '2000x2000', '2500x2500', '3000x3000', + '3500x3500', '4000x4000', '4000x4000', '4000x4000', '4000x4000'] + self.upSizes=[1024*256, 1024*256, 1024*512, 1024*512, + 1024*1024, 1024*1024, 1024*1024*2, 1024*1024*2, + 1024*1024*2, 1024*1024*2] + self.postData="" self.TestSpeed() @@ -353,10 +356,14 @@ def TestUpload(self): url=self.server+"upload.php?x=" + str( time.time() ) sizes, took=[0,0] + data="" for i in range(0, len(self.upSizes)): - self.postData=urllib.urlencode({'upload6': ''.join(random.choice(string.ascii_uppercase) for x in range(self.upSizes[i])) }) + if len(data) == 0 or self.upSizes[i] != self.upSizes[i-1]: + #print "Generating new string to upload. Length: ", self.upSizes[i] + data=''.join("1" for x in xrange(self.upSizes[i])) + self.postData=urllib.urlencode({'upload6': data }) - sizes, took=self.AsyncRequest(url, 2, 1) + sizes, took=self.AsyncRequest(url, (i<4 and 1 or (i<6 and 2 or (i<6 and 4 or 8))), 1) print "Upload size: %0.2f MiB; Uploaded in %0.2f s" % (float(sizes)/1024/1024, took) print "\033[92mUpload speed: %0.2f MiB/s\033[0m" % ((float(sizes)/1024/1024)/took) @@ -371,14 +378,14 @@ def TestDownload(self): # Testing download speed sizes, took=[0,0] for i in range(0, len(self.downList)): - url=self.server+"random"+self.downList[i]+".jpg?x=1348097022034&y=3" + url=self.server+"random"+self.downList[i]+".jpg?x=" + str( time.time() ) + "&y=3" #print url - sizes, took=self.AsyncRequest(url, i<1 and 2 or (i>7 and 6 or 4)) + sizes, took=self.AsyncRequest(url, (i<1 and 2 or (i<6 and 4 or (i<10 and 6 or 8))) ) print("Download size: %0.2f MiB; Downloaded in %0.2f s") % (float(sizes)/1024/1024, took) print("\033[91mDownload speed: %0.2f MiB/s\033[0m") % ((float(sizes)/1024/1024)/took) - if took>7: + if took>5: break #print "Download size: %0.2f MiB; Downloaded in %0.2f s" % (float(sizes)/1024/1024, took)