aspose file tools*
The moose likes I/O and Streams and the fly likes NIO and performance question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "NIO and performance question" Watch "NIO and performance question" New topic
Author

NIO and performance question

alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
Hi, I'm studying NIO. While I'm studying that NIO increases IO performances, I've written a simple "Hello World" program to see some of the NIO features. The first time I run the sample, however, it takes forever to allocate a simple ByteBuffer of 5 elements.
Shouldn't NIO improve performances?


Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
NIO generally can improve performance, but not always. Several features of NIO are efficient for handling a large number of bytes, but not so good (relatively) for small files. This includes FileChannel's map() method, and direct buffering.
Could you show the code you're using here? And what does "forever" mean here? milliseconds? Seconds? Worse?


"I'm not back." - Bill Harding, Twister
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
...snip...
Could you show the code you're using here? And what does "forever" mean here? milliseconds? Seconds? Worse?[/QB]

Certainly! Here follows the code:

For "forever" I mean 10 seconds, that, to write and read 5 bytes seems too much to me.
Marco
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
That's odd. I modified the main function as follows:

And ran the program. It printed this:

Approximately 0 milliseconds seems like the appropriate length of time given that a ByteBuffer is, after all, just an overglorified array.
alzamabar
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
I obtain the same results. The only thing is that I'm runnin the program from within Eclipse and it takes a while from when I run this program to when I receive the results (CERTAINLY NOT approx. 0 millisecs!).
The funny thing is that this delay occurs only when I run this program.
Never minds, thank you for your time and the good thing is...That I can use NIO with more confidence now!
Marco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NIO and performance question
 
Similar Threads
NIO and Internationalization
Simple Java Application
Strange question about character encoding
Creating a nonblocking stream
Multiplexing streams?