Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .github/bench/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { once } from "node:events";
import { resolve } from "node:path";
import { homedir } from "node:os";

const DEFAULT_ENGINES = ["http-native", "bun"];
const DEFAULT_ENGINES = ["http-native", "bun", "express"];
const DEFAULT_SCENARIOS = ["static", "dynamic", "opt"];
const DEFAULT_CONNECTIONS = 200;
const DEFAULT_DURATION = "10s";
Expand All @@ -22,6 +22,7 @@ const SERVER_PORTS = Object.freeze({
xitca: { static: 3003, dynamic: 3013, opt: 3023 },
monoio: { static: 3004, dynamic: 3014, opt: 3024 },
zig: { static: 3005, dynamic: 3015, opt: 3025 },
express: { static: 3008, dynamic: 3018, opt: 3028 },
fiber: { static: 3009, dynamic: 3019, opt: 3029 },
});

Expand Down Expand Up @@ -325,8 +326,18 @@ async function runBenchmarkCase(testCase, options) {
}

function spawnServer(testCase, options) {
if (testCase.engine === "bun" || testCase.engine === "http-native" || testCase.engine === "old") {
const runtime = testCase.engine === "bun" ? "bun" : options.httpNativeRuntime;
if (
testCase.engine === "bun" ||
testCase.engine === "http-native" ||
testCase.engine === "old" ||
testCase.engine === "express"
) {
const runtime =
testCase.engine === "bun"
? "bun"
: testCase.engine === "express"
? "node"
: options.httpNativeRuntime;
return spawn(runtime, [".github/bench/target.js", testCase.engine, testCase.scenario, String(testCase.port)], {
cwd: process.cwd(),
detached: process.platform !== "win32",
Expand Down
11 changes: 8 additions & 3 deletions .github/bench/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const httpNativeRuntime = runtimeArg ?? "bun";

function printUsage() {
console.log("Usage: bun .github/bench/run.js <engine> <scenario> <port> [httpNativeRuntime]");
console.log("Engines: http-native | bun | fiber | xitca | monoio | zig");
console.log("Engines: http-native | bun | express | fiber | xitca | monoio | zig");
console.log("Scenarios: static | dynamic | opt");
console.log("httpNativeRuntime: bun | node (only applies to http-native and old)");
console.log("");
Expand All @@ -33,7 +33,7 @@ function benchmarkPathForScenario(activeScenario) {
}

async function main() {
if (!["http-native", "bun", "fiber", "xitca", "monoio", "zig"].includes(engine)) {
if (!["http-native", "bun", "express", "fiber", "xitca", "monoio", "zig"].includes(engine)) {
printUsage();
process.exit(1);
}
Expand All @@ -48,7 +48,12 @@ async function main() {
process.exit(1);
}

const targetRuntime = engine === "http-native" || engine === "old" ? httpNativeRuntime : "bun";
const targetRuntime =
engine === "http-native" || engine === "old"
? httpNativeRuntime
: engine === "express"
? "node"
: "bun";

const child =
engine === "xitca" || engine === "monoio"
Expand Down
39 changes: 39 additions & 0 deletions .github/bench/target.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,49 @@ async function startFrameworkServer(createApp, label, activeScenario) {
});
}

async function startExpressServer(activeScenario) {
const { default: express } = await import("express");
const app = express();

if (activeScenario === "static") {
app.get("/", (_req, res) => {
res.json(buildStaticPayload("express"));
});
} else if (activeScenario === "dynamic") {
app.get("/users/:id", (req, res) => {
res.json({
id: req.params.id,
engine: "express",
mode: "dynamic",
});
});
} else {
app.get("/stable", (_req, res) => {
res.json(buildOptimizedPayload("express"));
});
}

app.use((_req, res) => {
res.status(404).json({ error: "Route not found" });
});

const server = app.listen(port, "127.0.0.1", () => {
console.log(`READY http://127.0.0.1:${port}`);
});

process.on("SIGTERM", () => {
server.close(() => {
process.exit(0);
});
});
}

if (engine === "bun") {
startBunServer("bun", scenario);
} else if (engine === "http-native") {
await startFrameworkServer(createHttpNativeApp, "http-native", scenario);
} else if (engine === "express") {
await startExpressServer(scenario);
} else if (engine === "old") {
const { createApp: createOldApp } = await import("../../old/src/index.js");
await startFrameworkServer(createOldApp, "old", scenario);
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ on:
workflow_dispatch:
inputs:
engines:
description: 'Comma-separated engines to benchmark. Supported by this workflow default run: "http-native,bun"'
description: 'Comma-separated engines to benchmark. Supported by this workflow default run: "http-native,bun,express"'
required: false
default: "http-native,bun"
default: "http-native,bun,express"
scenarios:
description: 'Comma-separated scenarios: "static,dynamic,opt"'
required: false
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
- name: Run benchmarks (http-native on Bun + selected engines)
run: |
bun .github/bench/ci.js \
--engines="${{ inputs.engines || 'http-native,bun' }}" \
--engines="${{ inputs.engines || 'http-native,bun,express' }}" \
--scenarios="${{ inputs.scenarios || 'static,dynamic,opt' }}" \
--connections="${{ inputs.connections || '200' }}" \
--duration="${{ inputs.duration || '10s' }}" \
Expand Down
143 changes: 143 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
"postinstall": "bun scripts/ensure-native.mjs || node scripts/ensure-native.mjs",
"setup:native": "bun scripts/setup-native.mjs || node scripts/setup-native.mjs",
"test": "bun run build && bun .github/tests/test.js && bun .github/tests/test-dev.js"
},
"devDependencies": {
"express": "^5.1.0"
}
}
Loading