Data is now incompressible

This commit is contained in:
dosse91 2016-11-28 21:09:12 +01:00
parent ec223a45d4
commit d9c320aee4
3 changed files with 26 additions and 28 deletions

View file

@ -1,8 +1,8 @@
# Speedtest in 4k # HTML5 Speedtest
No Flash, No Java, No Websocket, No Bullshit. No Flash, No Java, No Websocket, No Bullshit.
This is a very small Speedtest implemented in Javascript, using XMLHttpRequest and Web Workers. This is a very lightweight Speedtest implemented in Javascript, using XMLHttpRequest and Web Workers.
## Try it ## Try it
[Take a Speedtest](http://speedtest.adolfintel.com) [Take a Speedtest](http://speedtest.adolfintel.com)
@ -13,9 +13,9 @@ Only modern browsers are supported (Edge 12+)
## Requirements ## Requirements
- A reasonably fast web server - A reasonably fast web server
- Some way to generate garbage data using either the included PHP script, a [big file of random data](http://downloads.adolfintel.com/geth.php?r=speedtest-bigfile), or a symlink to /dev/urandom - Some way to generate garbage data using either the included PHP script, a [big file of random data](http://downloads.adolfintel.com/geth.php?r=speedtest-bigfile), or a symlink to /dev/urandom
- Your server must not compress the data it sends
- Your server must accept large POST requests (up to 10 Megabytes), otherwise the upload test will fail - Your server must accept large POST requests (up to 10 Megabytes), otherwise the upload test will fail
- Client side, there must not be any type of buffering (such as a proxy), or you may get incorrect results - Client side, there must not be any type of buffering (such as a proxy), or you may get incorrect results
- It's also better if your server does not use compression, but it's not mandatory
## How to use ## How to use
See the examples, it's really simple. See the examples, it's really simple.

View file

@ -1,5 +1,5 @@
<?php <?php
// Disable Compression (would be too easy for 000...) // Disable Compression
@ini_set('zlib.output_compression', 'Off'); @ini_set('zlib.output_compression', 'Off');
@ini_set('output_buffering', 'Off'); @ini_set('output_buffering', 'Off');
@ini_set('output_handler', ''); @ini_set('output_handler', '');
@ -15,8 +15,8 @@ header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false); header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); header("Pragma: no-cache");
// Generate data // Generate data
$data=str_repeat("0",1048575)."\n"; $data=openssl_random_pseudo_bytes(1048576,false);
// Deliver chunks of 1048576 bytes (or more - depending on encoding!) // Deliver chunks of 1048576 bytes
while(1){ while(1){
echo $data; echo $data;
flush(); flush();

View file

@ -1,32 +1,29 @@
var testStatus=0,dlStatus="",ulStatus="",pingStatus=""; var testStatus=0,dlStatus="",ulStatus="",pingStatus="";
var settings={time_ul:15, time_dl:15, count_ping:35, url_dl:"garbage.php",url_ul:"empty.dat",url_ping:"empty.dat"}; var settings={time_ul:15,time_dl:15,count_ping:35,url_dl:"garbage.php",url_ul:"empty.dat",url_ping:"empty.dat"};
var xhr=null; var xhr=null;
this.addEventListener('message', function(e){ this.addEventListener('message', function(e){
var params=e.data.split(" "); var params=e.data.split(" ");
if(params[0]=="status"){ if(params[0]=="status"){
postMessage(testStatus+";"+dlStatus+";"+ulStatus+";"+pingStatus); postMessage(testStatus+";"+dlStatus+";"+ulStatus+";"+pingStatus);
} }
if(params[0]=="start"){ if(params[0]=="start"&&testStatus==0){
if(testStatus==0){ testStatus=1;
testStatus=1; try{
try{ var s=JSON.parse(e.data.substring(5));
var s=JSON.parse(e.data.substring(5)); if(typeof s.url_dl != "undefined") settings.url_dl=s.url_dl;
if(typeof s.url_dl != "undefined") settings.url_dl=s.url_dl; if(typeof s.url_ul != "undefined") settings.url_ul=s.url_ul;
if(typeof s.url_ul != "undefined") settings.url_ul=s.url_ul; if(typeof s.url_ping != "undefined") settings.url_ping=s.url_ping;
if(typeof s.url_ping != "undefined") settings.url_ping=s.url_ping; if(typeof s.time_dl != "undefined") settings.time_dl=s.time_dl;
if(typeof s.time_dl != "undefined") settings.time_dl=s.time_dl; if(typeof s.time_ul != "undefined") settings.time_ul=s.time_ul;
if(typeof s.time_ul != "undefined") settings.time_ul=s.time_ul; if(typeof s.count_ping != "undefined") settings.count_ping=s.count_ping;
if(typeof s.count_ping != "undefined") settings.count_ping=s.count_ping; }catch(e){}
}catch(e){} dlTest(function(){testStatus=2;ulTest(function(){testStatus=3;pingTest(function(){testStatus=4;});});});
dlTest(function(){testStatus=2;ulTest(function(){testStatus=3;pingTest(function(){testStatus=4;});});});
}
} }
if(params[0]=="abort"){ if(params[0]=="abort"){
try{if(xhr)xhr.abort();}catch(e){} try{if(xhr)xhr.abort();}catch(e){}
testStatus=5;dlStatus="";ulStatus="";pingStatus=""; testStatus=5;dlStatus="";ulStatus="";pingStatus="";
} }
}); });
function dlTest(done){ 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();
@ -54,10 +51,9 @@ function dlTest(done){
xhr=null; xhr=null;
done(); done();
}.bind(this); }.bind(this);
xhr.open("GET", settings.url_dl+"?r="+Math.random(),true); xhr.open("GET",settings.url_dl+"?r="+Math.random(),true);
xhr.send(); xhr.send();
} }
function ulTest(done){ 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();
@ -82,10 +78,12 @@ function ulTest(done){
ulStatus="Fail"; ulStatus="Fail";
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);
xhr.send(new ArrayBuffer(10485760)); xhr.setRequestHeader('Content-Encoding','identity');
var r=new ArrayBuffer(10485760);
try{var w=new Float32Array(r);for(var i=0;i<w.length;i++)w[i]=Math.random();}catch(e){}
xhr.send(r);
} }
function pingTest(done){ function pingTest(done){
var prevT=null,ping=0.0,i=0; var prevT=null,ping=0.0,i=0;
var doPing=function(){ var doPing=function(){
@ -110,4 +108,4 @@ function pingTest(done){
xhr.send(); xhr.send();
}.bind(this); }.bind(this);
doPing(); doPing();
} }