Create A Java Variable (String) of a specific size (MB's)
Posted
by Bernie Perez
on Stack Overflow
See other posts from Stack Overflow
or by Bernie Perez
Published on 2010-03-19T01:40:43Z
Indexed on
2010/03/19
1:51 UTC
Read the original article
Hit count: 300
I am trying to benchmark some code. I am sending a String msg over sockets. I want to send 100KB, 2MB, and 10MB String variables. Is there an easy way to create a variable of these sizes?
Currently I am doing this.
private static String createDataSize(int msgSize) {
String data = "a";
while(data.length() < (msgSize*1024)-6) {
data += "a";
}
return data;
}
But this takes a very long time. Is there a better way?
© Stack Overflow or respective owner