• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

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
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???

Posts: 9626
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.
Blood pressure normal? What do I change to get "magnificent"? Maybe this tiny ad?
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic