This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Performance issue between C++ and Java on reading Large binary files  RSS feed

 
Denise Advincula
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,

I have a C++ program that reads a binary file of 1 million records (16000000 bytes size). It does some search, computation, etc and then displays the data and computation results in the console.

I did a java program with the same logic as that of my first program, though not using the same file but accessing the same file structure and size of 16000000 bytes.

For 1 million records, when ran on linux:

C++ program: speed of 2 seconds (max), cpu utilization of 66% (max)
Java program: speed of 18 seconds (max), cpu utilization of 100% (max)

I was a bit disappointed because I thought it would produce the same performance. And the thing is, the C++ program isn't that optimized as compared to the Java program. C++ program have a lot (as in lots) of for-loops per record, etc (thing is, it was programmed like a beginner). The Java program has the same logic but a little optimized: e.g.: minimized number of loops (like from 9 to 2 for-loops per record), no more System.out use...

Can anyone share me some insights on how to optimize my Java program more? Or make it perform like that of C++'s results?

Thanks in advance!

 
Jaydeep Mazumdar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Denise,

Which Java stream class are you using to read the file? Are you using buffering? Would it be possible for you to share the Java code for reading the file?

Here are some general guidelines that you can follow to improve the performance:

http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/

http://www.javaworld.com/jw-11-2000/jw-1117-performance.html?page=1

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!