DEV Community

2bitornot2bit - Ben Amsallem
2bitornot2bit - Ben Amsallem

Posted on

PERFORMANCE OF JVM VS NATIVE VS THE WORLD

Lately I was trying to understand
how virtual memory works
and how JVM work and perform.
My intuition was ' if a JVM is written in C, it is probably less performant than C '
So after a lot of reading and investigations I found out that the story is much more complicated then I have initially thought.
JVM has many optimization which makes it very fast most of the time, it does has an overhead but the optimization in JIT make everything worth it.
basically the JVM will loaded into native virtual memory (and be shared with other processes when possible)
it will use sophisticated algorithms to allocate memory on the native heap to create managed heap.
it will JIT to perform well, will vectorise actions and what not to make the run time overhead worth it.
At that point I was thinking ' OK, so javascript is a VM, it should probably also perform well '
But benchmark tests online showed different things. I know javascript is single threaded but this tests take this into account (For example fork many process).
The V8 engine is highly optimized and make all kind of clever things to perform faster, for example making a behind the scene classes and types and caches to speed up the execution.
V8 is still young compared to C and Java so I am sure it will be even better. my impression is that optimizing a dynamic language such as javascript is harder than a language like java, but I might be wrong here.

Any way I thought that I have to make my own test to better understand the performance difference in various situations, so here it is, my results

  1. ​java and node win when performing loops and in memory

  2. c and go win as of for reading file from disk to memory

  3. java wins in http server

hope you will find this info helpful!

Comments are more the welcome.

I also have a blog with other interesting stuff:

https://www.2bitornot2bit.com/blog

Oldest comments (0)