• Post Reply Bookmark Topic Watch Topic
  • New Topic

Converting an String to bytes  RSS feed

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I have come across an interesting piece of code and just want a confirmation of my understanding of it. If i have a string whicH i want to convert into a series of bytes using UTF-16 encoding i can use the String method getBytes by passing it the name of the encoding set to use.

I have found this piece of code that does the exact same thing.

I am persuming that the second piece of code will run faster than the first and as a result this is why someone can write it. I ran a basic test myself and my guess seems to be confirmed. Can anyone tell me if im correct and also why the second method is faster than the first.
thanks,
John
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second method is faster as it does not use the CharToByteConverter abstract factory to create a converter specific to the destination encoding.
Did you find very significant difference in your benchmark when running the JVM in server mode?
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try JDK 1.4? The character encoding stuff is much improved in 1.4.
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Beno�t d'Oncieu:
The second method is faster as it does not use the CharToByteConverter abstract factory to create a converter specific to the destination encoding.
Did you find very significant difference in your benchmark when running the JVM in server mode?

Ok thanks. I didnt get a change to run the JVM in server mode, just a quick test on my desktop where i called both pieces of code 1000 times and checked the time difference
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dave Landers:
Did you try JDK 1.4? The character encoding stuff is much improved in 1.4.


Well im stuck on 1.3.1 for this project but i must do some experimentation when i get some time.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!