Methodology: Crafting the Comparison
To gauge the performance of bun.sh against Node.js, we crafted a series of tests that mimic the behavior of recursive for loops. Using TypeScript, we implemented identical loop logic in both environments, tracking execution times and memory usage across varying depths of recursion.
The Approach to Recursive Loops
Recursive functions can quickly become resource-intensive, making them an excellent benchmark for runtime efficiency. Our tests involved implementing a recursive algorithm that calculated the sum of a series of numbers, increasing the recursion depth with each iteration.
Each test was run multiple times to ensure consistency, and the results were carefully logged for analysis. The chosen recursive function was designed to push the runtimes to their limits, providing a clear picture of their performance under pressure.
Analysis: Execution Time and Memory Usage
Initial Observations (Depths 1-3)
From the onset, both bun.sh and Node.js exhibited similar execution times, but a trend emerged showing bun.sh's superior memory efficiency. At depth 1, Node.js had a slightly lower mean execution time at 0.0142 ms compared to bun.sh’s 0.0161 ms, but it used considerably more memory (mean of 5.8652 MB for Node.js against 1.4089 MB for bun.sh). As we increased the depth, bun.sh began to outperform Node.js in both execution time and memory usage, which became more noticeable at depth 3, where bun.sh’s execution time mean was 0.1766 ms with a memory usage mean of 1.7949 MB, whereas Node.js posted a mean execution time of 0.2448 ms with a memory usage mean of 6.2239 MB.
Mid-Level Testing (Depths 4-6)
Moving into the mid-level depths, the gap widened. At depth 4, bun.sh’s mean execution time was 1.2596 ms, contrasting with Node.js’s 2.0537 ms. Memory usage remained more efficient for bun.sh, averaging 2.0944 MB compared to Node.js's 6.3826 MB. By depth 6, the difference in execution time was more pronounced; bun.sh averaged at 122.6465 ms, almost 35% faster than Node.js's 187.1683 ms. Regarding memory, bun.sh used an average of 2.5624 MB, maintaining its lead over Node.js, which averaged 6.9020 MB.
Deep Recursion (Depths 7-9)
As we ventured into the deeper levels of recursion, bun.sh's performance benefits became even more evident. At depth 7, bun.sh completed tasks with a mean execution time of 1232.1892 ms, whereas Node.js lagged behind with a mean of 1899.1045 ms. The memory usage for bun.sh was also lower, with a mean of 3.3887 MB compared to Node.js’s 7.8682 MB. This trend of bun.sh outpacing Node.js continued through depths 8 and 9, where bun.sh’s mean execution times were 15204.0159 ms and 163026.9187 ms respectively, against Node.js’s 18316.1047 ms and 183032.4489 ms. Memory usage figures at these depths further underscored bun.sh's efficiency, with its memory usage peaking at 12.7907 MB at depth 9, while Node.js peaked at 22.5308 MB.
% Less Memory Used
bun.sh Mean Time (ms)
node.js Mean Time (ms)
bun.sh Mean Memory (MB)
node.js Mean Memory (MB)
In this table, the data is grouped into three depth ranges, with averages calculated for each group. The fastest environment for each group is determined based on the mean execution time, and the percentages `faster` and `less memory used` are calculated accordingly.
Key Findings: When Performance Is Paramount
Throughout the depths tested, bun.sh has consistently showcased its prowess. Notably, in the early stages (Depths 1-3), it began to edge out Node.js by being 24.04% faster and using 73.65% less memory. This initial performance set the tone for the subsequent tests.
As we journeyed into the mid-range depths (4-6), bun.sh's performance lead solidified. It outpaced Node.js by a significant 34.31%, all the while maintaining a substantial lead in memory efficiency with 64.35% less memory usage. For developers, this performance advantage represents a substantial improvement, particularly in applications where execution speed is critical.
In the realm of deep recursion (Depths 7-9), bun.sh continued to surpass Node.js, completing tasks 13.32% faster and utilizing 51.13% less memory. These figures are not merely numbers; they translate into real-world efficiencies and savings in both time and resources.
The mean execution times and memory usage across all depths speak volumes about bun.sh's capabilities. Where Node.js presented a mean time of 68,249.2194 ms in the most intense depth bracket, bun.sh averaged at 59,154.3746 ms. That translates to nearly 9 seconds faster response in average. In terms of memory, while Node.js consumed a mean of 11.3358 MB, bun.sh required only 55.533 MB. A whopping 48.8% reduction.
Conclusion: A Decisive Victory for bun.sh in Performance
We encourage you to witness these results firsthand. Dive into the detailed reports, replicate our benchmarks, and see if bun.sh can elevate your applications to the next level of performance:
Our tests are a starting point. We invite the community to expand upon this work, challenge our findings, and contribute to a collective understanding. Will bun.sh continue to outperform as it matures? That's for the community to test, verify, and decide. But for now, in our tests, bun.sh stands as the unrivaled leader in recursive loop execution performance.