Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Application Windows vs Mac OS X

Tags:

java

macos

jvm

I developed a java application on a small windows desktop that parse XML files. I met a very interesting observation that I am very curious about.

I produced an executable jar for my application and ran it on Windows Server machine that is very powerful. It has 2 physical Xeon processors each 8 cores clocked at 2.7 GHz, 50GB RAM and 7200 RPM HDD. The machine was idle when I started my application and I am pretty sure no other application shared the machine with me.

Later, I was running the executable on my Macbook Pro for the sake of fun to see its behaviour. My personal machine is Core i7 clocked at 2.2 GHz with 4 GB RAM and 5400 RPM HDD.

Surprisingly, the application was twice faster on my personal weaker machine. It was the same input \ same output. No IO but for reading the XMLs to parse them, I print nothing on Terminal but Start Time \ End Time & Final result which is one line

I am very curious to understand the reason behind such a dramatic performance difference. Specially from a weaker machine on the level of the hardware. Is it the operating system that handles hardware in a better way?. Is it JVM working better?.

like image 781
mowienay Avatar asked Sep 25 '13 17:09

mowienay


1 Answers

On Windows default installations of JRE come with HotSpot Client compiler. This compiler does only basic optimizations, contrary to server HotSpot which does more aggressive optimizations and produces much faster code. Server HotSpot is default on most Unix-like and Linux distributions, including Mac OS X. The performance difference between those two compilers can be often 2-3x. The client HotSpot is optimized mostly for faster startup of desktop applications, not for top performance of long running processes.

To check which compiler you are using issue the following command:

java -version

On my machine it gives:

java version "1.6.0_45"
Java (TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
                        ^^^^^^  this

To get Server HotSpot on Windows, you need to download and install JDK and then run your program with -server command line switch.

like image 54
Piotr Kołaczkowski Avatar answered Sep 29 '22 15:09

Piotr Kołaczkowski