Quickly generate junk data of certain size in Javascript
Posted
by
user1357607
on Stack Overflow
See other posts from Stack Overflow
or by user1357607
Published on 2012-07-10T03:04:47Z
Indexed on
2012/07/10
3:15 UTC
Read the original article
Hit count: 159
I am writing an upload speed test in Javascript. I am using Jquery (and Ajax) to send chunks of data to a server in order to time how long it takes to get a response. This should, in theory give an estimation, of the upload speed.
Of course to cater for different bandwidths of the user I sequentially upload larger and larger amounts of junk data until a threshold duration is reached. Currently I generate the junk data using the following function, however, it is very slow when generation megabytes of data.
function generate_random_data(size){
var chars = "abcdefghijklmnopqrstuvwxyz";
var random_data = "";
for (var i = 0; i < size; i++){
var random_num = Math.floor(Math.random() * char.length);
random_data = random_data + chars.substring(random_num,random_num+1);
}
return random_data;
Really all I am doing is generating a chunk of bytes to send to the server, however, this is the only way I could find out how in Javascript.
Any help would be appreciated.
© Stack Overflow or respective owner