Skip to content

Instantly share code, notes, and snippets.

@fightbulc
Last active October 13, 2024 05:42
Show Gist options
  • Save fightbulc/ba7ff28bf2f88c9034a8f0ae1805e263 to your computer and use it in GitHub Desktop.
Save fightbulc/ba7ff28bf2f88c9034a8f0ae1805e263 to your computer and use it in GitHub Desktop.
Bun and Deno Bench (Ubuntu 24.04, AMD Ryzen™ 9 7900X × 24, 64GB RAM)
// will be called via bun-parallel-setup.ts
let i = 0;
Bun.serve({
port: process.env.PORT || 8000,
development: false,
// Share the same port across multiple processes
// This is the important part!
reusePort: true,
async fetch(request): Promise<Response> {
return new Response(`Hello World ${i++}`);
},
});
// bun bun-parallel-setup.ts
// oha -c 10 -n 10000000 --disable-compression http://localhost:8000
/**
Success rate: 100.00%
Total: 30.6906 secs
Slowest: 0.0015 secs
Fastest: 0.0000 secs
Average: 0.0000 secs
Requests/sec: 325833.0318
*/
import { spawn } from "bun";
const cpus = navigator.hardwareConcurrency; // Number of CPU cores
const buns = new Array(cpus);
for (let i = 0; i < cpus; i++) {
buns[i] = spawn({
cmd: ["bun", "bun-parallel-server.ts"],
stdout: "inherit",
stderr: "inherit",
stdin: "inherit",
});
}
function kill() {
for (const bun of buns) {
bun.kill();
}
}
process.on("SIGINT", kill);
process.on("exit", kill);
// bun bun.ts
// oha -c 10 -n 10000000 --disable-compression http://localhost:8000
/**
Success rate: 100.00%
Total: 67.4036 secs
Slowest: 0.0571 secs
Fastest: 0.0000 secs
Average: 0.0001 secs
Requests/sec: 148359.9817
*/
let i = 0;
Bun.serve({
port: 8000,
async fetch(request): Promise<Response> {
return new Response(`Hello World ${i++}`);
},
});
// deno serve --allow-net --parallel ./index.ts
// oha -c 10 -n 10000000 --disable-compression http://localhost:8000
/**
Success rate: 100.00%
Total: 35.3663 secs
Slowest: 0.0035 secs
Fastest: 0.0000 secs
Average: 0.0000 secs
Requests/sec: 282754.6559
*/
let i = 0;
export default {
async fetch(request: Request): Promise<Response> {
return new Response(`Hello World ${i++}`);
},
};
// deno serve --allow-net ./index.ts
// oha -c 10 -n 10000000 --disable-compression http://localhost:8000
/**
Success rate: 100.00%
Total: 84.2660 secs
Slowest: 0.0616 secs
Fastest: 0.0000 secs
Average: 0.0001 secs
Requests/sec: 118671.7597
*/
let i = 0;
export default {
async fetch(request: Request): Promise<Response> {
return new Response(`Hello World ${i++}`);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment