Benchmarks
Nixi includes a comprehensive benchmark suite to measure framework performance. Run benchmarks locally to compare with other frameworks or track optimization progress.
Quick Start
# Run Lua benchmarks
lua benchmarks/benchmark.lua
# Run HTTP benchmarks (requires server running)
lua benchmarks/server.lua # In one terminal
./benchmarks/http-benchmark.sh 3000 10 100 4 # In another
Micro Benchmarks
The micro benchmark suite tests core Lua operations:
Running
lua benchmarks/benchmark.lua
Sample Output
=================================================
Nixi Framework Benchmark
=================================================
Iterations: 100,000
Lua Version: Lua 5.4
1. String Operations
-------------------------------------------------
String concat 5.14M ops/s (0.0195s total)
String format 3.79M ops/s (0.0264s total)
Table concat 2.01M ops/s (0.0498s total)
2. Table Operations
-------------------------------------------------
Table insert 1.91M ops/s (0.0525s total)
Table iteration 2.15M ops/s (0.0465s total)
Array iteration 3.86M ops/s (0.0259s total)
3. Route Pattern Matching
-------------------------------------------------
Match: / 3.30M ops/s (0.0303s total)
Match: /users/:id 1.64M ops/s (0.0608s total)
Match: /api/v1/:resource/:id 1.15M ops/s (0.0873s total)
4. HTML Generation
-------------------------------------------------
Simple HTML string 63.98M ops/s (0.0016s total)
Dynamic HTML concat 8.17M ops/s (0.0122s total)
HTML table builder 289.56K ops/s (0.3453s total)
5. JSON Serialization
-------------------------------------------------
JSON encode (simple) 407.69K ops/s (0.2453s total)
JSON encode (nested) 110.82K ops/s (0.9023s total)
6. HTTP Response Simulation
-------------------------------------------------
Response (small) 1.39M ops/s (0.0721s total)
Response (JSON) 1.53M ops/s (0.0652s total)
=================================================
HTTP Benchmarks
HTTP benchmarks compare Nixi against other frameworks using wrk.
Requirements
# Install wrk (Ubuntu/Debian)
sudo apt install wrk
# macOS
brew install wrk
Running
# Terminal 1: Start test server
lua benchmarks/server.lua
# Terminal 2: Run benchmarks
./benchmarks/http-benchmark.sh 3000 10 100 4
Test Endpoints
| Endpoint | Type | Description |
|---|---|---|
/text |
Plain Text | Simple text response |
/ |
HTML | Full HTML page |
/json |
JSON | JSON response |
/users/:id |
Dynamic | Route with parameter |
/api/posts/:id |
API | Nested API route |
Parameters
./http-benchmark.sh [port] [duration] [connections] [threads]
# Examples:
./http-benchmark.sh 3000 # Default: 10s, 100 conn, 4 threads
./http-benchmark.sh 3001 30 200 8 # Stress test: 30s, 200 conn, 8 threads
Framework Comparison
To compare Nixi with other frameworks, start each server on a different port:
# Terminal 1: Nixi server
lua benchmarks/server.lua # Runs on port 3000
# Terminal 2: Flask server (example)
FLASK_APP=app.py flask run -p 3001 # Runs on port 3001
# Terminal 3: Express server (example)
node server.js 3002 # Runs on port 3002
# Terminal 4: Run comparisons
./benchmarks/http-benchmark.sh 3000 > nixi-results.txt
./benchmarks/http-benchmark.sh 3001 > flask-results.txt
./benchmarks/http-benchmark.sh 3002 > express-results.txt
Key Metrics
Operations Per Second
| Operation | Typical Range | Notes |
|---|---|---|
| String concatenation | 5-10M ops/s | Highly optimized in LuaJIT |
| Table operations | 2-5M ops/s | Core Lua data structure |
| Route matching | 1-3M ops/s | Pattern compilation cached |
| HTML generation | 8-15M ops/s | String building |
| JSON serialization | 100-500K ops/s | Varies by library |
HTTP Throughput
Expected throughput on localhost (varies by hardware):
| Endpoint | Requests/sec | Latency (p50) |
|---|---|---|
| /text | 50K-150K | < 0.5ms |
| /json | 40K-120K | < 0.6ms |
| / | 30K-100K | < 1ms |
| /users/:id | 25K-80K | < 1.5ms |
Optimization Tips
- Use LuaJIT: 2-5x faster than vanilla Lua for numeric code
- Cache patterns: Pre-compile route patterns on startup
- Batch operations: Use table.concat for building large strings
- Profile first: Use
luajit -jpto identify bottlenecks