SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
Thread: Javascript & Unexpected Results
-
Sep 17, 2003, 11:16 #1
- Join Date
- Feb 2001
- Posts
- 136
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Javascript & Unexpected Results
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 :
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 :-)
-
Sep 17, 2003, 13:15 #2
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's my version of a javascript bandwidth test. You'll have to clear your cache to run it more than once, though.
http://www.peterbailey.net/test/bandwidth.htm
-
Sep 17, 2003, 16:56 #3
- Join Date
- Feb 2001
- Posts
- 136
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Do you mind if I "steal" your sources and play around with them.
-
Sep 17, 2003, 16:59 #4
- Join Date
- Jul 2002
- Location
- Dallas, TX
- Posts
- 2,900
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Go right ahead. Copyright notices are included where I wish them to be [img]images/smilies/biggrin.gif[/img]
Oh, and I changed to the cache header on the image, so clearing your cache isn't necessary to re-run the test.
-
Sep 18, 2003, 04:22 #5
- Join Date
- Feb 2001
- Posts
- 136
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by beetle
Using your code and variations of mine I have actually got this thing working it still reports infinity & 0 from time to time but no where near as often as the orignal version.
One final thing that I am curious about is the image file you use in your code :
http://www.peterbailey.net/test/image.php
You mentioned that you have changed the cache header on the image to prevent cache issues, how did you achieve this? and is it possible to do without php?
-
Sep 18, 2003, 09:11 #6
Bookmarks