A Simple Performance Test and Difference: Go v/s Java

Sunny Radadiya
2 min readMay 19, 2019

--

Go v/s Java

This is the short article to check Performance between Golang and Java Programming.

My system configuration is 16 GB RAM, Intel(R) Core(TM) i7–8550U CPU 2.00GHz and 500 GB SSD.

I have simply written a factorial program using Go and Java languages and make an analysis table and Time chart for various inputs.

Let’s first Check with the Go lang

Output:Factorial   Time To calculate factorial
10000 0.03 seconds
50000 0.41 seconds
100000 2.252 seconds
500000 68.961 seconds
1000000 224.135 seconds

Let’s Check for Java

Output:Factorial   Time To calculate factorial
10000 0.112 seconds
50000 1.185 seconds
100000 2.252 seconds
500000 89.500 seconds
1000000 385.868 seconds

Comparison using Chart

Time Chart For Go and Java

Here, from the above programs, we can see that time taken by Go is lesser than Java for various inputs.

Why Go is Faster than Java?

Go is compiled to machine code and is executed directly, which makes it much faster than Java. It is so because Java uses VM to run its code which makes it slower as compared to Golang.

Golang is also good in memory management, which is crucial in programming languages. Golang does not have references but has pointers.

In the case of local variables also, Golang is better as compared to Java. Local variables are stored on the stack in the Java language and other languages. But there is an exception to this in Golang, it can return a pointer to a local variable from a function.

For more details: https://metalop.com/2016/08/24/is-golang-better-than-java/

Conclusion

I have been exploring Go language for some time and it seems pretty interesting language. It is not a replacement for Java even on a language level. That is not the purpose of this article. Go lang and Java are not supposed to serve the same type of tasks — Java is enterprise development language whereas Go is a system programming language. Now we practically know why is amongst the fastest languages in terms of execution time.

That’s it, folks. Thanks for reading. If you liked what you read, don’t forget to clap! Happy coding!

Check out my other article on Golang.

https://medium.com/@radadiyasunny970/go-lang-rest-api-using-gorilla-mux-a7dafbb64214

--

--

Sunny Radadiya

Blockchain Enthusiast | Ethereum Developer | Go Developer | Ethereum Sharding