Skip to content

Commit 5c8c4d5

Browse files
committed
Push all examples
1 parent 7eea5b7 commit 5c8c4d5

44 files changed

Lines changed: 9017 additions & 299 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/benchmark.yml

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Benchmark
2+
3+
on:
4+
# Run on PRs to compare performance
5+
pull_request:
6+
paths:
7+
- 'packages/**'
8+
- 'benchmark/**'
9+
# Manual trigger
10+
workflow_dispatch:
11+
inputs:
12+
suite:
13+
description: 'Benchmark suite to run'
14+
required: false
15+
default: 'all'
16+
type: choice
17+
options:
18+
- all
19+
- micro
20+
- memory
21+
- streaming
22+
# Weekly scheduled run for tracking
23+
schedule:
24+
- cron: '0 0 * * 0' # Every Sunday at midnight
25+
26+
jobs:
27+
benchmark-native:
28+
name: Native Benchmarks
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Setup OCaml
35+
uses: ocaml/setup-ocaml@v3
36+
with:
37+
ocaml-compiler: 5.2.x
38+
dune-cache: true
39+
40+
- name: Install dependencies
41+
run: opam install . --deps-only --with-test -y
42+
43+
- name: Build benchmark scenarios
44+
run: opam exec -- dune build benchmark/scenarios/benchmark_scenarios.a
45+
46+
- name: Build benchmark executables
47+
run: |
48+
opam exec -- dune build benchmark/micro/micro_bench.exe
49+
opam exec -- dune build benchmark/memory/memory_bench.exe
50+
opam exec -- dune build benchmark/streaming/streaming_bench.exe
51+
52+
- name: Run Memory Benchmark
53+
id: memory
54+
run: |
55+
echo "## Memory Benchmark Results" >> $GITHUB_STEP_SUMMARY
56+
echo '```' >> $GITHUB_STEP_SUMMARY
57+
opam exec -- _build/default/benchmark/memory/memory_bench.exe 2>&1 | tee memory-results.txt
58+
cat memory-results.txt >> $GITHUB_STEP_SUMMARY
59+
echo '```' >> $GITHUB_STEP_SUMMARY
60+
61+
- name: Run Streaming Benchmark
62+
id: streaming
63+
run: |
64+
echo "## Streaming Benchmark Results" >> $GITHUB_STEP_SUMMARY
65+
echo '```' >> $GITHUB_STEP_SUMMARY
66+
opam exec -- _build/default/benchmark/streaming/streaming_bench.exe 2>&1 | tee streaming-results.txt
67+
cat streaming-results.txt >> $GITHUB_STEP_SUMMARY
68+
echo '```' >> $GITHUB_STEP_SUMMARY
69+
70+
- name: Run Microbenchmark (Quick)
71+
id: micro
72+
run: |
73+
echo "## Microbenchmark Results (Table Suite)" >> $GITHUB_STEP_SUMMARY
74+
echo '```' >> $GITHUB_STEP_SUMMARY
75+
opam exec -- _build/default/benchmark/micro/micro_bench.exe table 2>&1 | tee micro-results.txt
76+
cat micro-results.txt >> $GITHUB_STEP_SUMMARY
77+
echo '```' >> $GITHUB_STEP_SUMMARY
78+
79+
- name: Upload Results
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: benchmark-results-${{ github.sha }}
83+
path: |
84+
memory-results.txt
85+
streaming-results.txt
86+
micro-results.txt
87+
retention-days: 30
88+
89+
benchmark-compare:
90+
name: Compare with Base Branch
91+
runs-on: ubuntu-latest
92+
if: github.event_name == 'pull_request'
93+
94+
steps:
95+
- uses: actions/checkout@v4
96+
with:
97+
fetch-depth: 0
98+
99+
- name: Setup OCaml
100+
uses: ocaml/setup-ocaml@v3
101+
with:
102+
ocaml-compiler: 5.2.x
103+
dune-cache: true
104+
105+
- name: Install dependencies
106+
run: opam install . --deps-only --with-test -y
107+
108+
- name: Benchmark PR branch
109+
run: |
110+
opam exec -- dune build benchmark/memory/memory_bench.exe
111+
opam exec -- _build/default/benchmark/memory/memory_bench.exe --json > pr-results.json
112+
113+
- name: Checkout base branch
114+
run: git checkout ${{ github.base_ref }}
115+
116+
- name: Benchmark base branch
117+
run: |
118+
opam exec -- dune clean
119+
opam exec -- dune build benchmark/memory/memory_bench.exe
120+
opam exec -- _build/default/benchmark/memory/memory_bench.exe --json > base-results.json
121+
continue-on-error: true
122+
123+
- name: Compare Results
124+
run: |
125+
echo "## Performance Comparison" >> $GITHUB_STEP_SUMMARY
126+
echo "" >> $GITHUB_STEP_SUMMARY
127+
if [ -f base-results.json ] && [ -f pr-results.json ]; then
128+
echo "Comparing memory allocations between base and PR..." >> $GITHUB_STEP_SUMMARY
129+
# Simple comparison - in production you'd use a proper tool
130+
echo "Base branch results:" >> $GITHUB_STEP_SUMMARY
131+
echo '```json' >> $GITHUB_STEP_SUMMARY
132+
cat base-results.json >> $GITHUB_STEP_SUMMARY
133+
echo '```' >> $GITHUB_STEP_SUMMARY
134+
echo "" >> $GITHUB_STEP_SUMMARY
135+
echo "PR branch results:" >> $GITHUB_STEP_SUMMARY
136+
echo '```json' >> $GITHUB_STEP_SUMMARY
137+
cat pr-results.json >> $GITHUB_STEP_SUMMARY
138+
echo '```' >> $GITHUB_STEP_SUMMARY
139+
else
140+
echo "⚠️ Could not compare - base branch benchmark may not exist" >> $GITHUB_STEP_SUMMARY
141+
fi
142+

benchmark/Makefile

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Server Reason React Benchmark Suite
2+
# ==================================
3+
4+
.PHONY: all build build-native build-js clean help
5+
.PHONY: bench bench-micro bench-memory bench-streaming bench-http
6+
.PHONY: native-server js-servers
7+
8+
# Directories
9+
BENCHMARK_DIR := $(shell pwd)
10+
PROJECT_ROOT := $(shell dirname $(BENCHMARK_DIR))
11+
RESULTS_DIR := $(BENCHMARK_DIR)/results
12+
FRAMEWORKS_DIR := $(BENCHMARK_DIR)/frameworks
13+
14+
# Default target
15+
all: help
16+
17+
# ============================================================================
18+
# Build Targets
19+
# ============================================================================
20+
21+
build: build-native build-js
22+
@echo "✓ All builds complete"
23+
24+
build-native:
25+
@echo "Building native OCaml benchmarks..."
26+
cd $(PROJECT_ROOT) && dune build benchmark/scenarios/benchmark_scenarios.a
27+
cd $(PROJECT_ROOT) && dune build benchmark/native/server.exe
28+
cd $(PROJECT_ROOT) && dune build benchmark/micro/micro_bench.exe
29+
cd $(PROJECT_ROOT) && dune build benchmark/memory/memory_bench.exe
30+
cd $(PROJECT_ROOT) && dune build benchmark/streaming/streaming_bench.exe
31+
@echo "✓ Native builds complete"
32+
33+
build-js:
34+
@echo "Building JavaScript frameworks..."
35+
cd $(FRAMEWORKS_DIR) && npm install
36+
@echo "✓ JavaScript frameworks ready"
37+
38+
clean:
39+
cd $(PROJECT_ROOT) && dune clean
40+
rm -rf $(RESULTS_DIR)/*.json $(RESULTS_DIR)/*.md
41+
rm -rf $(FRAMEWORKS_DIR)/node_modules
42+
@echo "✓ Cleaned"
43+
44+
# ============================================================================
45+
# Benchmark Targets
46+
# ============================================================================
47+
48+
# Run all benchmarks
49+
bench: bench-micro bench-memory bench-streaming bench-http
50+
@echo "✓ All benchmarks complete"
51+
52+
# Microbenchmarks (Core_bench)
53+
bench-micro: build-native
54+
@echo "\n=== Running Microbenchmarks ==="
55+
$(PROJECT_ROOT)/_build/default/benchmark/micro/micro_bench.exe all
56+
57+
bench-micro-suite: build-native
58+
@echo "Available suites: trivial, depth, width, table, props, realworld, primitives, all"
59+
@if [ -z "$(SUITE)" ]; then \
60+
echo "Usage: make bench-micro-suite SUITE=<name>"; \
61+
else \
62+
$(PROJECT_ROOT)/_build/default/benchmark/micro/micro_bench.exe $(SUITE); \
63+
fi
64+
65+
# Memory benchmarks
66+
bench-memory: build-native
67+
@echo "\n=== Running Memory Benchmarks ==="
68+
$(PROJECT_ROOT)/_build/default/benchmark/memory/memory_bench.exe
69+
70+
bench-memory-json: build-native
71+
@mkdir -p $(RESULTS_DIR)
72+
$(PROJECT_ROOT)/_build/default/benchmark/memory/memory_bench.exe --json > $(RESULTS_DIR)/memory-$$(date +%Y%m%d-%H%M%S).json
73+
74+
# Streaming/render benchmarks
75+
bench-streaming: build-native
76+
@echo "\n=== Running Streaming Benchmarks ==="
77+
$(PROJECT_ROOT)/_build/default/benchmark/streaming/streaming_bench.exe
78+
79+
# HTTP load testing (requires wrk)
80+
bench-http: build
81+
@echo "\n=== Running HTTP Benchmarks ==="
82+
@mkdir -p $(RESULTS_DIR)
83+
cd $(BENCHMARK_DIR)/runner && node runner.mjs
84+
85+
bench-http-quick: build
86+
@echo "\n=== Running Quick HTTP Benchmarks ==="
87+
cd $(BENCHMARK_DIR)/runner && node runner.mjs --scenarios trivial,table100
88+
89+
# Framework-specific HTTP benchmarks
90+
bench-native-http: build-native
91+
@echo "\n=== Running Native HTTP Benchmarks ==="
92+
cd $(BENCHMARK_DIR)/runner && node runner.mjs --frameworks dream-native
93+
94+
bench-js-http: build-js
95+
@echo "\n=== Running JavaScript HTTP Benchmarks ==="
96+
cd $(BENCHMARK_DIR)/runner && node runner.mjs --frameworks node-express,node-fastify,hono-node
97+
98+
# ============================================================================
99+
# Server Targets (for manual testing)
100+
# ============================================================================
101+
102+
native-server: build-native
103+
@echo "Starting native Dream server on port 3000..."
104+
PORT=3000 $(PROJECT_ROOT)/_build/default/benchmark/native/server.exe
105+
106+
js-servers: build-js
107+
@echo "Starting all JavaScript servers..."
108+
cd $(FRAMEWORKS_DIR) && npm run start:all
109+
110+
# Individual JS servers
111+
node-express: build-js
112+
cd $(FRAMEWORKS_DIR) && npm run start:node-express
113+
114+
node-fastify: build-js
115+
cd $(FRAMEWORKS_DIR) && npm run start:node-fastify
116+
117+
hono-node: build-js
118+
cd $(FRAMEWORKS_DIR) && npm run start:hono-node
119+
120+
# ============================================================================
121+
# Utility Targets
122+
# ============================================================================
123+
124+
# Quick load test with wrk (requires running server)
125+
wrk-test:
126+
@if [ -z "$(PORT)" ]; then \
127+
echo "Usage: make wrk-test PORT=3000 [SCENARIO=table100]"; \
128+
else \
129+
wrk -t4 -c100 -d10s "http://localhost:$(PORT)/?scenario=$${SCENARIO:-table100}"; \
130+
fi
131+
132+
# Show scenarios available
133+
scenarios: build-native
134+
@$(PROJECT_ROOT)/_build/default/benchmark/native/server.exe &
135+
@sleep 1
136+
@curl -s http://localhost:3000/scenarios | jq .
137+
@pkill -f "server.exe" || true
138+
139+
# Open results
140+
results:
141+
@ls -la $(RESULTS_DIR)/*.md $(RESULTS_DIR)/*.json 2>/dev/null || echo "No results yet. Run 'make bench-http'"
142+
143+
# ============================================================================
144+
# Help
145+
# ============================================================================
146+
147+
help:
148+
@echo "Server Reason React Benchmark Suite"
149+
@echo "===================================="
150+
@echo ""
151+
@echo "Build targets:"
152+
@echo " make build - Build all (native + JS)"
153+
@echo " make build-native - Build native OCaml benchmarks"
154+
@echo " make build-js - Install JS framework dependencies"
155+
@echo " make clean - Clean all build artifacts"
156+
@echo ""
157+
@echo "Benchmark targets:"
158+
@echo " make bench - Run all benchmarks"
159+
@echo " make bench-micro - Run microbenchmarks (Core_bench)"
160+
@echo " make bench-micro-suite SUITE=<name>"
161+
@echo " - Run specific suite (trivial|depth|width|table|props|realworld|primitives|all)"
162+
@echo " make bench-memory - Run memory benchmarks"
163+
@echo " make bench-streaming - Run streaming benchmarks"
164+
@echo " make bench-http - Run HTTP load testing (all frameworks)"
165+
@echo " make bench-http-quick - Quick HTTP test (trivial + table100 only)"
166+
@echo " make bench-native-http - HTTP test native only"
167+
@echo " make bench-js-http - HTTP test JS frameworks only"
168+
@echo ""
169+
@echo "Server targets (for manual testing):"
170+
@echo " make native-server - Start native Dream server (port 3000)"
171+
@echo " make js-servers - Start all JS servers"
172+
@echo " make node-express - Start Node.js + Express"
173+
@echo " make node-fastify - Start Node.js + Fastify"
174+
@echo " make hono-node - Start Hono + Node.js"
175+
@echo ""
176+
@echo "Utility:"
177+
@echo " make wrk-test PORT=3000 [SCENARIO=table100]"
178+
@echo " - Quick load test against running server"
179+
@echo " make scenarios - List available scenarios"
180+
@echo " make results - Show benchmark results"
181+

0 commit comments

Comments
 (0)