File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes file2String faster code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "file2String faster code" Watch "file2String faster code" New topic
Author

file2String faster code

Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
What will be faster file2String ?

this :


or :

Thank you!
Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
or this:


Thank you
Sharon
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Have you tried to profile any of them?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'd be interested to hear where you got the code for the last example. It is almost correct, but actually quite crazy.

In general:
Buffered streams will be better.
StringBuffers will be better.
Reading into a buffer rather than per character will be better.
Readers and Writers will be better for character data.

You may also like to like at the NIO classes.

Are you trying to solve a problem, just playing, design a component or have some other aim?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Originally posted by David O'Meara:
It is almost correct, but actually quite crazy.


I take that back, it is a variable with the name 'L', not a number 'one'. Calling it 'len' or 'length' would cause less confusion.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Originally posted by Sharon whipple:
What will be faster file2String ?

this :


or :

Thank you!


These seem like hard work. How about


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Sharon whipple
Ranch Hand

Joined: Jul 31, 2003
Posts: 294
Results :
test0 : Runs: 241 iterations ,avarage milis = 246
test1 : Runs: 249 iterations ,avarage milis = 118
test2 : Runs: 269 iterations ,avarage milis = 5
test3 : Runs: 241 iterations ,avarage milis = 2

TestClass :
Roger F. Gay
Ranch Hand

Joined: Feb 16, 2007
Posts: 396
Wow. That's quite a difference.


Correlation does not prove causality.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file2String faster code