This repository contains benchmarks for measuring the startup time of a Moonbeam node using different JavaScript/TypeScript runtimes.
Benchmark 1: native:bun
Time (mean ± σ): 4.281 s ± 0.097 s [User: 22.953 s, System: 0.491 s]
Range (min … max): 4.133 s … 4.411 s 10 runs
Benchmark 2: native:node
Time (mean ± σ): 5.153 s ± 0.066 s [User: 24.277 s, System: 0.584 s]
Range (min … max): 5.065 s … 5.294 s 10 runs
Benchmark 3: docker:node
Time (mean ± σ): 5.332 s ± 0.104 s [User: 2.419 s, System: 0.211 s]
Range (min … max): 5.170 s … 5.517 s 10 runs
Benchmark 4: docker:bun
Time (mean ± σ): 4.404 s ± 0.078 s [User: 0.758 s, System: 0.116 s]
Range (min … max): 4.286 s … 4.562 s 10 runs
Time (mean ± σ): 6.151 s ± 0.104 s [User: 2.744 s, System: 0.273 s]
Range (min … max): 6.061 s … 6.407 s 10 runs
Summary
native:bun ran
1.03 ± 0.03 times faster than docker:bun
1.20 ± 0.03 times faster than native:node
1.25 ± 0.04 times faster than docker:node
1.44 ± 0.04 times faster than testcontainers:node
- Install Node.js v23
# Using nvm (recommended)
nvm install 23
nvm use 23
- Install Bun
curl -fsSL https://bun.sh/install | bash
- Install Hyperfine
# On Ubuntu/Debian
sudo apt-get install hyperfine
# On macOS
brew install hyperfine
Download the latest Moonbeam binary from the official releases:
# Download latest binary (example for Linux)
wget https://github.com/moonbeam-foundation/moonbeam/releases/latest/download/moonbeam
# Make it executable
chmod +x moonbeam
Note
The moonbeam
binary is already in .gitignore
.
- Clone the repository
- Install dependencies:
bun install
- Compile the TypeScript:
bun run compile
To run the native benchmarks individually:
- Using Bun:
bun run native
- Using Node:
bun run native:node
- Using Docker with Bun:
bun run docker
- Using Docker with Node:
bun run docker:node
- Using Testcontainers with Node:
node --import tsx scripts/testcontainers.ts
To run the complete benchmark comparison (includes all methods):
bun run bench
This will compare the following implementations:
- Native implementation with Bun
- Native implementation with Node
- Docker implementation with Node
- Docker implementation with Bun
- Testcontainers implementation with Node
The project includes multiple Docker-based implementations:
-
Direct Docker API: Uses the
dockerode
package to directly interact with the Docker daemon. This implementation can be found inscripts/docker.ts
. -
Testcontainers: Uses the
testcontainers
package which provides a more testing-oriented approach to container management. This implementation can be found inscripts/testcontainers.ts
.
Both implementations:
- Pull and run the
moonbeamfoundation/moonbeam
container - Configure the necessary ports (9944)
- Set up the required node arguments
- Handle container lifecycle management
- Install Docker on your system
- Make sure the Docker daemon is running
- Ensure your user has permissions to interact with Docker
To manage Docker containers manually:
# Pull the Moonbeam image
docker pull moonbeamfoundation/moonbeam
# List running containers
docker ps
# Stop all running containers (if needed)
docker stop $(docker ps -q)