Performance comparison of Java and C++ when sorting integers and writing/reading files.

University essay from Blekinge Tekniska Högskola/Institutionen för datavetenskap

Author: Suraj Sharma; [2019]

Keywords: Programming; software; java; c ; performance;

Abstract: This study is conducted to show the strengths and weaknesses of C++ and Java in three areas that are used often in programming; loading, sorting and saving data.Performance and scalability are large factors in software development and choosing the right programming language is often a long process.It is important to conduct these types of direct comparison studies to properly identify strengths and weaknesses of programming languages. Two applications were created, one using C++ and one using Java.Apart from a few syntax and necessary differences, both are as close to being identical as possible.Each application loads three files containing 1000, 10000 and 100000 randomly ordered integers.These files are pre-created and always contain the same values.They are randomly generated by another small application before testing. The test runs three times, once for each file.When the data is loaded, it is sorted using quicksort.The data is reset using the dataset file and sorted again using insertion-sort.The sorted data is then saved to a file.Each test runs 50 times in a large loop and the times for loading, sorting and saving the data are saved.In total, 300 tests are run between the C++ and the Java application. The results show that Java has a total time that is faster than C++ and it is also faster when loading two out of three datasets.C++ was generally faster when sorting the datasets using both algorithms and when saving the data to files. In general Java was faster in this study, but when processing the data and when under heavy load, C++ performed better.The main difference was when loading the files.The way that Java loads the data from a file is very different from C++, even though both applications read the files character by character, Java’s “Scanner” library converts data before it parses it.With some optimization, for example by reading the file line by line and then parsing the data, C++ could be comparable or faster, but for the sake of this study, the input methods that were chosen were seemingly the fairest.

  AT THIS PAGE YOU CAN DOWNLOAD THE WHOLE ESSAY. (follow the link to the next page)