Pau Sanchez
Programming, technology & business

Dummy web benchmark with nim, zig, go, bun, node, python

Last week Daniel Lemire published a simple hello world web benchmark in multiple languages.

There were a couple of things that picked my interest:

  • bun.sh was supposed to be faster (the initial post was using bun+fastify, which was not optimal)
  • nim ranking was certainly a surprise as well (Nim is a language that resembles python but is natively compiled).

Some of the toy experiments from Lemire’s blog were slightly biased in the original post, since some of the toy web servers were returning “hello world” and some others “hello”, plus some had some sort of routing, while others did not. Overal performance was similar, but I thought it was a good idea to update all tests locally to return the exact same string and use same exact routing to keep the same spirit on all the servers. Lemire later updated his blog with more languages.

Last week, when I read the article I downloaded the source code from Lemire’s blog and did some local changes and experiments to play around. Here are my results with different languages / frameworks after updating slightly the test and including some more:

Language+FrameworkRequestsThroughtputversion
nim182k rpm29.30MB/snim 2.0.0
nim168k rpm27.00MB/snim 1.4.0
zig+zap159k rpm32.70MB/szig 0.11 - ReleaseFast
go+fiber142k rpm26.69MB/sgo 1.18.1 + fiber v2
go+fiber137k rpm24.93MB/sgo 1.21.2 + fiber v2
go113k rpm20.50MB/sgo 1.18.1
go105k rpm19.16MB/sgo 1.21.2
bun (native)74.5k rpm13.44MB/sbun 1.0.3
node (native)32k rpm7.22MB/snode v20.8.0
bun+fastify27k rpm4.86MB/sbun 1.0.3
python+fastapi8k rpm1.68MB/spython 3.10.12

I used same command Lemire was using on his initial post:

$ bombardier -c 10 http://localhost:3000/simple

Here is the computer I used:

  • CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
  • RAM: 32GB

I added Python just to compare, and although I was expecting it to be slower than other frameworks, I thought it would be faster that what I got. It was kind of a disappointment.

These results are orientative, but give a good sense on how different languages/frameworks are preforming high-level. Feel free to take these results with a grain of salt, though.

Anyway, usually real-world performance depends on lots of other factors (IO, database, network conditions, …).

In the ideal world I should be providing the source code, environment, etc…but hey, I just did this to play around. If you want, you can find some source code on Lemire’s post to get started. Either way, if you feel courious, I would encourage you to run your own experiments.

Finally, kind of unrelated, but if you want to continue reading something interesting, it just came to mind a series of 3 articles on improving javascript performance to rank well on Techempower rankings:

I remember it was an interesting read at the time.

Have fun.