Sorry for the vague title to the thread, but I couldnt think of a simple way of putting the problem that I have come up agaisnt.
I have been tasked with putting together a simple bandwidth test tool that can run through a browser with the least amount of user interaction. To do this I have created a javascript that downloads an image, times this download, reloads the page passing the values from the previous test - my current script iterates ten times.
The problem that I have encountered is that when I view the summary results at the end of the test run, alot of the timings are either "infinite" or "0" and these are randomly placed in the results, i.e. if I re-run the script I will get infinite or 0 on different sets.
The code I am using is as follows :
When the script gets to the 11 iteration it dives out to another page that simply displays the results of the test run, for the sake of post size I havent included the code here as all it is is a simple script that takes the command line args splits them up by ":" and pumps the results into a table.Code:<!-- //set vars var Request = new QSHandler(); var imageBase = Request.QueryString("img"); var recurCount = Request.QueryString("cnt"); var filesize = Request.QueryString("fls"); var timings = Request.QueryString("tim"); var throughputs = Request.QueryString("thr"); var imageName = imageBase + recurCount + ".bmp"; var startTime; var endTime; //display image & start timer if (recurCount != 11) { document.write("<center><img height=150 width=150 onload=endTimer() src="+imageName+"></center>"); document.write("<center><font face=verdana size=2>"+imageName+" / " + filesize + " bytes</center>"); startTime = new Date(); } else { document.location = "downloadrecurse_summary.htm?&img=" + imageBase +"&thr=" + throughputs + "&tim=" + timings; } //set functions function endTimer() { var endTime = new Date(); var totalTime = ( endTime.getTime() - startTime.getTime() ) / 1000; //seconds var throughput = Math.round(((filesize / totalTime) / 1024) * 100)/100; //kbytes/sec //see http://javascriptkit.com/javatutors/round.shtml for rounding description if (recurCount == 1) { timings = totalTime; throughputs = throughput; } else { timings += ":" + totalTime; throughputs += ":" + throughput; } recurCount++; document.location = "downloadrecurse.htm?img=" + imageBase + "&fls=" + filesize + "&cnt=" + recurCount + "&thr=" + throughputs + "&tim=" + timings; } function QSHandler() { var qs = location.search.substr(1).split("&"); this.data = []; for(var i = 0; i < qs.length; i++) this.data[qs[i].split("=")[0]] = qs[i].split("=")[1]; this.QueryString = function(x) { return this.data[x]; }; } // -->
A typical results table looks like this :
Run / Time (secs) / throughput (kbs)
Run 1 - 0 - Infinity
Run 2 - 0 - Infinity
Run 3 - 0.016 - 612.18
Run 4 - 0 - Infinity
........
As somebody who has about 24 hours experience in Javascript I am sure that I am missing something here that is blatently obvious to most if not all, I wont admit that I have failed, rather acknowledge that I have found a 1000 ways that it doesnt work :-)





Bookmarks