Improved accuracy; Minor changes and fixes
This commit is contained in:
parent
858bfe61a1
commit
f1bf2ce2ae
1 changed files with 10 additions and 8 deletions
|
@ -28,7 +28,7 @@ function dlTest(done){
|
||||||
var firstTick=true,startT=new Date().getTime(), prevT=new Date().getTime(),prevLoaded=0,speed=0.0;
|
var firstTick=true,startT=new Date().getTime(), prevT=new Date().getTime(),prevLoaded=0,speed=0.0;
|
||||||
xhr=new XMLHttpRequest();
|
xhr=new XMLHttpRequest();
|
||||||
xhr.onprogress=function(event){
|
xhr.onprogress=function(event){
|
||||||
var instspd=(event.loaded-prevLoaded)/((new Date().getTime()-prevT)/1000.0);
|
var instspd=event.loaded<=0?prevLoaded:((event.loaded-prevLoaded)/((new Date().getTime()-prevT)/1000.0));
|
||||||
if(isNaN(instspd)||!isFinite(instspd)) return;
|
if(isNaN(instspd)||!isFinite(instspd)) return;
|
||||||
if(firstTick){
|
if(firstTick){
|
||||||
speed=instspd;
|
speed=instspd;
|
||||||
|
@ -42,9 +42,9 @@ function dlTest(done){
|
||||||
if(((prevT-startT)/1000.0)>settings.time_dl){try{xhr.abort();}catch(e){} xhr=null; done();}
|
if(((prevT-startT)/1000.0)>settings.time_dl){try{xhr.abort();}catch(e){} xhr=null; done();}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
xhr.onload=function(){
|
xhr.onload=function(){
|
||||||
dlStatus=((speed*8)/1048576.0).toFixed(2);
|
prevT=new Date().getTime(); prevLoaded=0; fistTick=true;
|
||||||
xhr=null;
|
xhr.open("GET",settings.url_dl+"?r="+Math.random(),true);
|
||||||
done();
|
xhr.send();
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
xhr.onerror=function(){
|
xhr.onerror=function(){
|
||||||
dlStatus="Fail";
|
dlStatus="Fail";
|
||||||
|
@ -58,12 +58,12 @@ function ulTest(done){
|
||||||
var firstTick=true,startT=new Date().getTime(), prevT=new Date().getTime(),prevLoaded=0,speed=0.0;
|
var firstTick=true,startT=new Date().getTime(), prevT=new Date().getTime(),prevLoaded=0,speed=0.0;
|
||||||
xhr=new XMLHttpRequest();
|
xhr=new XMLHttpRequest();
|
||||||
xhr.upload.onprogress=function(event){
|
xhr.upload.onprogress=function(event){
|
||||||
var instspd=(event.loaded-prevLoaded)/((new Date().getTime()-prevT)/1000.0);
|
var instspd=event.loaded<=0?prevLoaded:((event.loaded-prevLoaded)/((new Date().getTime()-prevT)/1000.0));
|
||||||
if(isNaN(instspd)||!isFinite(instspd)) return;
|
if(isNaN(instspd)||!isFinite(instspd)) return;
|
||||||
if(firstTick){
|
if(firstTick){
|
||||||
firstTick=false;
|
firstTick=false;
|
||||||
}else{
|
}else{
|
||||||
speed=speed*0.7+instspd*0.3;
|
speed=instspd<speed?(speed*0.4+instspd*0.6):(speed*0.8+instspd*0.2);
|
||||||
}
|
}
|
||||||
prevLoaded=event.loaded;
|
prevLoaded=event.loaded;
|
||||||
prevT=new Date().getTime();
|
prevT=new Date().getTime();
|
||||||
|
@ -71,11 +71,13 @@ function ulTest(done){
|
||||||
if(((prevT-startT)/1000.0)>settings.time_ul){try{xhr.abort();}catch(e){} xhr=null; done();}
|
if(((prevT-startT)/1000.0)>settings.time_ul){try{xhr.abort();}catch(e){} xhr=null; done();}
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
xhr.onload=function(){
|
xhr.onload=function(){
|
||||||
ulStatus=((speed*8)/1048576.0).toFixed(2);
|
prevT=new Date().getTime(); prevLoaded=0; fistTick=true;
|
||||||
done();
|
xhr.open("POST",settings.url_ul+"?r="+Math.random(),true);
|
||||||
|
xhr.send(r);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
xhr.onerror=function(){
|
xhr.onerror=function(){
|
||||||
ulStatus="Fail";
|
ulStatus="Fail";
|
||||||
|
xhr=null;
|
||||||
done();
|
done();
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
xhr.open("POST",settings.url_ul+"?r="+Math.random(),true);
|
xhr.open("POST",settings.url_ul+"?r="+Math.random(),true);
|
||||||
|
|
Loading…
Reference in a new issue