all groups > vj# > june 2004 >
You're in the

vj#

group:

Performance of String allocation


Performance of String allocation fsnow NO[at]SPAM fsnow.com
6/28/2004 11:47:50 AM
vj#:
I have an application that allocates a large number of strings using
the String(byte[] bytes, int offset, int length) constructor. A simple
test case shows that string allocation is between one and two orders
of magnitude slower in J# relative to JVM 1.4.

Here's the code:

int dataLength = 200000;
int numStrings = 6000;
int strLength = 100;
int offsetIncrement = (dataLength - strLength) / numStrings;
byte[] data = new byte[dataLength];
new Random().nextBytes(data);
String[] strs = new String[numStrings];
long start = System.currentTimeMillis();
int j = 0;
for (int i = 0; i < numStrings; i++)
{
strs[i] = new String(data, j, strLength);
j += offsetIncrement;
}
long end = System.currentTimeMillis();
long duration = end - start;
System.out.println("Elapsed time: " + new Long(duration).toString());


JVM 1.4: 160 ms
J#: 11086 ms


Has anyone seen this before?

Re: Performance of String allocation Lars-Inge Tønnessen
6/28/2004 10:02:20 PM

http://osnews.com/story.php?news_id=5602&page=3

Someone in the J# team posted a message a while ago, and told us performance
was a big issue in the next release of J#.

I/O is very bad today...


Regards,
Larsr-Inge Tønnessen

Re: Performance of String allocation Calvin Clark [MSFT]
9/8/2004 3:18:09 PM

[quoted text, click to view]

You might note that if you modify the code so that data array is char[]
rather that byte[], the performance is much better. When the string
constructor takes a byte array, it has to do a lot of work dealing the the
character set encodings. This is probably done more efficiently in the
current Java libraries than in the J# string helper classes in vjslib.dll.
I don't think it has anything to do with String allocation per se. Just a
speculation...

-Calvin

AddThis Social Bookmark Button