Java Processing Speed Test With & Without PrintStream(System.out)

Posted on Posted in Java, Software

I wrote this Java code for fun to benchmark the running process with and without displaying the current progress. This algorithm exhibits the performance drawback when the status displaying is actively refreshing in the command line.

What is this Java code doing?

For testing Java’s PrintStream(System.out) performance I decided to use MD5 hash calculation. This script is nothing fancy, it runs from command line with two arguments supplied to it, which are simple text files (path to the files). The first file contains the MD5 hash – or multiple hashes separated with carriage returns – stored as a text file. The following file is the password list in readable format also separated with carriage returns.  The process will load one password and calculate its MD5 hash which then matched with the other one. If it fails – I’m assured that it is going to – then it tries the next password and so on.

When a password fails a number displays in the command line, which increments with the number of failed tries. Time is measured in milliseconds,  the starting value is set right before the loop and the ending when the loop is finished. The difference between the two values is the elapsed time. The process runs twice, without and with the status counter. After the two cycles are finished the code exits leaving the two test results in the console.

The Java source code

The code can be viewed here or downloaded from along with the sample hash and password files. There is only one hash in the sample file and 1 million passwords in the other one.

For outputting the process counter I used System.out which declared as an instance of PrintStream class. This is the main function which can dramatically slow down the whole process.

Password files can be very large, they could take even 85Gb. Reading them into the memory is a very bad practice. For that reason FileStream class is an acceptable solution. It streams the file byte-by-byte making the application efficient and suitable for larger files.

If you want to increase the counter step just change the value of password.modulus property in the main() function. In my first cycle it is set to password.modulus = 0 to not to display the progress counter. The second cycle has a setting password.modulus = 1 to show every failed tries. Setting it password.modulus = 1000 will refresh the counter after every 1000th failed tries therefore the process will be faster.

Compiling and usage

After installing Java Development Kit, compiling the source code is very simple.

To be able to run the application:

Result of the benchmark

After running the following command I had the following results.

Test 1 shows that, trying 1,000,000 passwords against a MD5 hash and not showing the counter after every failed tries, would take only 1.386 seconds. That is around 721,500 passwords/second. The Total passwords started at 0 and jumped to 1000000 after the task finished. In Test 2, the counter number was incrementally displayed after every failed tries by PrintStream(System.out). The process took 26.507 seconds which is around 37,725 passwords/seconds. This is 94.7713% slower than Test 1!!!

Leave a Reply

Your email address will not be published. Required fields are marked *