• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NIO and performance question

 
alzamabar
Ranch Hand
Posts: 379
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
alzamabar
Ranch Hand
Posts: 379
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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
Posts: 1365
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 379
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic