This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Is NIO really faster than java.io.*

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have always used the java.io. classes for java IO. I tried to compare the performance of the io and nio classes FileChannel and ByteBuffers with the normal FileInput/OutputStreams and found that the normal java io was faster than nio.
I wrote a simple program that reads a file into a ByteBuffer/Byte Array and writes the output to a FileOutputStream/ByteBuffer.
The ByteBuffer requires additional operations that might be resulting in a delay. After every read you need to do a flip on a ByteBuffer and before every read(), you need to clear the buffer. These operations might be causing delays.
The code for the two approaches:





The Old IO class took less than 1 milisecond to complete and the new io class took 20 miliseconds to complete.

Any thoughts???

Thanks
Sameer
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The java.io.* classes are implemented using NIO (for example, FileInputStream has a getChannel() method) so the speed difference between the two should be negligable. The improvement NIO introduced was not speed, but new and interesting functionality that java.io.* did not have. See this article for some examples.
reply
    Bookmark Topic Watch Topic
  • New Topic