š§ Bun Frameworks
Well, by now you probably figured that I like to prefix the āTheā in each blog post section, so letās keep that going! Oh, also having an emoji for the title - yes, I know, Bunās mascot is a, well, bun, but there is not bun emoji, so I had to improvise.
Anyway, letā go back on topic!
The Problem
This blog post is actually about the performance between different Bun frameworks. I asked a question on X, formerly known as Twitter, but of course didnāt get an response, since I really donāt have a following there (or anywhere for that matter š).
Now, because my blog is still pretty new and needs more content, I decided to write a blog post about it. I mean, why not? Itās a good topic, right? Right?
Letās get started!
The Setup
As for the test tools, I will be using:
- Laptop - MacBook Pro 16-inch, 2021, 32GB RAM with the Apple M1 Max chip on Sonoma 14.4.1.
- Bun v1.1.3
You will find the full codebase on GitHub: github.com/bobalazek/bun-frameworks
One thing that I did differently in this case is, that instead of tools like locust, goose, bombaridier or similar, I decided to quickly write my own benchmarking tool in Bun of course. At the end it doesnāt matter, as we basically only care about the relative performance difference between the different frameworks.
Here is the list of frameworks that I will be testing:
- Bun - https://bun.sh
- ElysiaJS - https://elysiajs.com
- Hono - https://hono.dev
- H3 - https://h3.unjs.io
- Hattip - https://github.com/hattipjs/hattip
- Fastify - https://www.fastify.io
- Express - https://expressjs.com
- Koa - https://koajs.com
- Hapi - https://hapi.dev
The Results
This is by no means a scientific test, but it should give you a rough idea of the performance of the different Bun frameworks. I have ran the test and took a result that seems to be the most consistent. Each framework receives 100.000 requests and the response text for each request is āHello, World!ā.
Framework | Average RPS | Cold start (ms) | Average (ms) | Median (ms) | Mean (ms) | 75th perc. (ms) | 95th perc. (ms) | 99th perc. (ms) | Std. (ms) |
---|---|---|---|---|---|---|---|---|---|
bun | 28778 | 22.989 | 0.035 | 0.033 | 0.035 | 0.035 | 0.042 | 0.065 | 0.024 |
elysiajs | 28762 | 10.070 | 0.035 | 0.032 | 0.035 | 0.035 | 0.043 | 0.074 | 0.025 |
hono | 28295 | 9.596 | 0.035 | 0.033 | 0.035 | 0.036 | 0.042 | 0.066 | 0.023 |
hattip | 27746 | 6.442 | 0.036 | 0.034 | 0.036 | 0.036 | 0.043 | 0.066 | 0.026 |
fastify | 22527 | 12.610 | 0.044 | 0.040 | 0.044 | 0.043 | 0.056 | 0.088 | 0.042 |
h3 | 21079 | 4.334 | 0.047 | 0.044 | 0.047 | 0.047 | 0.058 | 0.091 | 0.033 |
koa | 20872 | 14.236 | 0.048 | 0.043 | 0.048 | 0.046 | 0.063 | 0.095 | 0.047 |
hapi | 18919 | 17.766 | 0.053 | 0.047 | 0.053 | 0.051 | 0.064 | 0.102 | 0.052 |
express | 18779 | 9.864 | 0.053 | 0.048 | 0.053 | 0.052 | 0.065 | 0.101 | 0.048 |
- RPS (Requests Per Second) - purely looking at the number of requests per second, we can see that ElysiaJS, Hono and Bun are very close to each other, with ElysiaJS being the fastest. Hattip is also very close, with a negligible difference. H3 did surprise me a bit, as from what I read it should be faster, but itās not. Fastify, H3 and Koa are slower, with Hapi and Express being the slowest as expected.
- Cold Start - the time it takes for the first request to be served. Hattip takes the crown Headers, with ElysiaJS and Hono being very close. Bun surprisingly is the slowest of all here, which I am not really sure why. I ran the benchmark multiple times and I always get the same results.
- Other Response Times - ElysiaJS, Hono and Bun are again very close to each other, with basically rounding-error differences. Hattip a tiny bit slower, but still very close. Fastify, H3 and Koa are slower, with Hapi and Express being the slowest again.
The Conclusion
I am not really sure what to make of these results. I was expecting ElysiaJS to be the fastest, but I didnāt expect Hono and Bun to be so close. I also didnāt expect Hattip to be so close to the top. H3 was a bit of a surprise, as I was expecting it to be faster.
At the end of the day, raw speed is not the only thing that matters. There are many other factors that you need to consider when choosing a framework, such as ease of use, community support, documentation, etc.
The End
I hope you enjoyed this blog post and found it useful. If you have any questions, feel free to reach out to me on X, formerly known as Twitter, or via email.
Until next time! š