This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • 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 wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic