HighTechTalks DotNet Forums  

Performance of String allocation

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Performance of String allocation in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default Performance of String allocation - 06-28-2004 , 02:47 PM






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?

FS

Reply With Quote
  #2  
Old   
Calvin Clark [MSFT]
 
Posts: n/a

Default Re: Performance of String allocation - 09-08-2004 , 06:18 PM







"Frank Snow" <fsnow (AT) fsnow (DOT) com> wrote

Quote:
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?

FS
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




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.