Take a very common exercise on Leetcode, two-sum and implement the same solution in different languages and submit.
| Language | Runtime | Memory |
|---|---|---|
| Go | 20 ms | 6.5 MB |
| Python3 | 32 ms | 15.5 MB |
| Java | 3 ms | 42 MB |
Have you ever wondered about these striking differences?
Is Java really 7x faster than Go and 10x faster than Python?
And on the flipside, is Go memory footprint 7x lower than Java?
Leetcode runs the submission against a test suite, but what if you run millions of computations?
Since most applications are deployed as containers these days, what kind of performance would you get when deploying an algorythm such as two-sum on a Kubernetes cluster?
I pushed the experimentation all the way, and packaged the solution into a docker image for each language and deployed them to Kubernetes. A Redis counter is incremented for each computation.

Every image is deployed on a similar node (same VM type) and can run as many replicas as needed to maximize the throughput. This architecture provides a fair ground and rewards a language that can maximize the properties of containerization.
The full framework is open sourced on github.
Here are the results when running two-sum on a node with 2xCPU, 8GB RAM for 10 min.
| Lang | Count(millions) |
|---|---|
| go | 26.10 |
| java | 88.89 |
| python | 13.41 |
And now comparing with Leetcode results:
| Lang | LeetCode | rainbow |
|---|---|---|
| java vs go (Runtime) | 7x | 3.5x |
| java vs python (Runtime) | 10x | 6.5x |
| java vs go (Memory) | 3x | 12x |
| java vs python (Memory) | 6x | 6.5x |
A few comments:
I also did the same experiment for generic implementations such as Hashtable, File IO, Sort, N-square array and tested with Go, Java, Python, Ruby and Rust. See all results here.
I thought some of you might be interested by these results and might have fun trying out your code in docker-compose or kubernetes using your favorite programming languages.
Detail of the experiment and source code shared on github:
https://github.com/RemyDeWolf/rainbow/blob/master/MEDIUM.md
Please let me know if you have any questions, I will be happy to answer in comments.
Thanks,
Remy