gitmyhub

bun-vs-node-sea-startup

JavaScript ★ 47 updated 3mo ago

This repository is a speed test comparing how fast two different JavaScript runtimes—Node.js and Bun—can start up when their code is bundled into a single executable file. If you've ever wished your CLI tool or script started instantly instead of taking a noticeable pause, this benchmark measures which approach wins.

The test works by taking a large, realistic TypeScript codebase (500 modules with thousands of functions) and packaging it in four different ways. Two approaches use Node.js's "Single Executable Application" feature—one basic version and one with extra caching turned on. The other two use Bun's built-in compilation, again with and without an optimization called bytecode. Then the benchmark runs each packed-up program 30 times on a cold start (when nothing is cached by the OS) and measures how long it takes to finish. The results show that Bun's bytecode approach is fastest at about 111 milliseconds, while the basic Node.js approach takes around 161 milliseconds.

You'd use this repository if you're trying to decide between Node.js and Bun for building fast, self-contained command-line tools—the kind where users download a single binary and run it without needing to install Node first. It answers the practical question: which one actually starts faster in real conditions? The benchmark is careful to be realistic, including different kinds of code patterns (classes, error handling, regex, closures) that mirror what actual applications do.

The project is notable because it doesn't just measure raw speed; it also shows the tradeoff with binary size. Bun's fastest option (with bytecode) produces an 83 MB file, while Node.js versions range from 115 to 117 MB. The code is reproducible and tunable—you can adjust how large and complex the test workload is to match your own real-world scenario—making this useful as a template for benchmarking your own applications across both runtimes.