Hello, friends!
I vahe a problem using prototype1.4 in IE6.
I am trying to create bandwidth speed test tool. The idea is to
download one by one X times (i.e. 10) one and the same ASCII-file with
size = 1MB. I would like to measure time and speed of each run, to
display the intermediate results after aech run and finally after all
X rund display total results as average of all runs.
But when I run my script with 10 iterations and 1MB filesize on a
1Mbps link I get very strange numbers: about 2 seconds per iterations
or 10Mbps in less then 20 seconds! I tried to use asynchronous=false
option, but in this case my script doesnt run at all.
Please, help me to get rid of it. Maybe the problem in my false
understanding of prototype methods or completely false understanding
of Ajax technology, because I am quite novice to it.
With regards,
Zahhar Kirillov
P.S. I use the following code:
<!-- CLIENT SIDE -->
<script>
var runs = 10; //total count of iterations
var i = 0; //current iteration counter
var totaltime = 0; //total time of all completed iterations
var starttime = 0; // time the current iteration started
var endtime = 0; //time the current iteration ended
function starttest() { //main function
var time = new Date();
starttime = time.getTime(); //get starting time of this iteration
var myAjax = new Ajax.Request(''getfile.php'',{method:
''post'',
parameters: '''', onComplete: putresponse}); /*request for data
without
parameters*/}
function putresponse(response) {
var time = new Date();
endtime = time.getTime(); //get time of ineration end
var runtime = endtime-starttime; //get this iteration running time
totaltime=totaltime+runtime; //increase total time
$(''result'').innerHTML = response.responseText;
//output of a
returned data to invisible div
$(''timer'').innerHTML=$(''timer'').innerHTML+"<br
/>Run #"+i+":
"+(runtime)+"ms"; //output time and counter of current iteration
if(++i>=runs) { endtest(); } else { starttest(); } //if there
are more iterations to do, do it. else process the total time
information.
}
function endtest() {
$(''timer'').innerHTML=$(''timer'').innerHTML+"<br
/>Total:
"+(totaltime)+"ms"; } //output total time information
</script>
<a href="javascript:;" onClick="starttest();">Start
test!</a>
<div id="result" style="visibility:
hidden"></div><br />
<div id="timer"></div>
<!-- SERVER SIDE, getfile.php -->
<?php
$filename = "data.txt"; /*1MB of ASCII text without any special
chars*/
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
?>