added performance benchmarks to readme

Commit 2fe3789 · patx · 2025-01-29T03:18:56-05:00

Changeset
2fe3789f8554785062a0ec875da5834007f81032
Parents
476ef4cca8c962d67380effcd338ae4fb1e7aef6

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/MicroPie.py b/MicroPie.py
index 911ad7d..867cf7c 100644
--- a/MicroPie.py
+++ b/MicroPie.py
@@ -89,7 +89,6 @@ class Server:
             cookies = self._parse_cookies(headers_dict.get("cookie", ""))
 
             session_id = cookies.get("session_id")
-
             if session_id and session_id in self.sessions:
                 self.session = self.sessions[session_id]
                 self.session["last_access"] = time.time()
diff --git a/README.md b/README.md
index 104f742..c4521ba 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
 - 🎨 **Templates:** Jinja2, if installed, for rendering dynamic HTML pages.
 - ✨ **ASGI-Powered:** Built w/ asynchronous support for modern web servers like Uvicorn and Daphne, enabling high concurrency.
 - 🛠️ **Lightweight Design:** Minimal dependencies for faster development and deployment.
-- ⚡ **Blazing Fast:** Check out the [benchmarks](https://gist.github.com/patx/1269e389d7d19ea31eb3b9ffff47e0cb#file-micropie_fastapi_benchmarks-md)!
+- ⚡ **Blazing Fast:** Check out how MicroPie compares to other popular ASGI frameworks below!
 
 ## **Installing MicroPie**
 
@@ -171,8 +171,9 @@ ASGI is the future of Python web development, offering:
 MicroPie allows you to take full advantage of these benefits while maintaining simplicity and ease of use you're used to with your WSGI apps and it lets you choose what libraries you want to work with instead of forcing our ideas onto you!
 
 
-## **Feature Comparison**
+## **Comparisons**
 
+### **Features vs Other Popular Frameworks*
 | Feature             | MicroPie      | Flask        | CherryPy   | Bottle       | Django       | FastAPI         |
 |---------------------|---------------|--------------|------------|--------------|--------------|-----------------|
 | **Ease of Use**     | Very Easy     | Easy         | Easy       | Easy         | Moderate     | Moderate        |
@@ -182,7 +183,23 @@ MicroPie allows you to take full advantage of these benefits while maintaining s
 | **Async Support**   | Yes (ASGI)    | No (Quart)   | No         | No           | Limited      | Yes (ASGI)      |
 | **Built-in Server** | No            | No           | Yes        | Yes          | Yes          | No              |
 
-
+### **Performance vs Other ASGI Frameworks**
+| Framework   |   Threads |   Connections |   Duration (s) |   Requests/sec |   Latency (ms) |   Transfer/sec (KB) |
+|------------|----------:|--------------:|---------------:|---------------:|---------------:|--------------------:|
+| FastAPI     |         4 |           100 |             30 |        1895.29 |          52.67 |              257.54 |
+| MicroPie    |         4 |           100 |             30 |        2272.76 |          43.93 |              362.18 |
+| Quart       |         4 |           100 |             30 |        1500.13 |          66.63 |              212.68 |
+| Starlette   |         4 |           100 |             30 |        2305.50 |          43.30 |              326.88 |
+| FastAPI     |         4 |           200 |             30 |        2015.90 |          99.78 |              273.94 |
+| MicroPie    |         4 |           200 |             30 |        2516.01 |          79.31 |              400.92 |
+| Quart       |         4 |           200 |             30 |        1574.15 |         126.63 |              223.16 |
+| Starlette   |         4 |           200 |             30 |        2658.45 |          75.10 |              376.86 |
+| FastAPI     |         4 |          1000 |             30 |        2129.72 |         463.63 |              289.44 |
+| MicroPie    |         4 |          1000 |             30 |        2589.64 |         381.86 |              412.79 |
+| Quart       |         4 |          1000 |             30 |        1557.83 |         628.80 |              221.01 |
+| Starlette   |         4 |          1000 |             30 |        2887.07 |         342.99 |              409.37 |
+
+*Tests were performed with `uvicorn` using 4 workers. Benchmarked with `wrk`. This a minimal baseline benchmark, and should be taken with a grain of salt.*
 
 ## **Suggestions or Feedback?**
 We welcome suggestions, bug reports, and pull requests!
diff --git a/examples/hello_world/benchmarks/bench.sh b/examples/hello_world/benchmarks/bench.sh
deleted file mode 100755
index d396110..0000000
--- a/examples/hello_world/benchmarks/bench.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-
-# Test configuration
-TEST_DURATION="30s"   # Test for 30 seconds
-NUM_THREADS="2"       # Use 2 threads
-NUM_CONNECTIONS="1000" # 200 concurrent connections
-PORT="5000"
-URL="http://127.0.0.1:8000/"
-WRK_COMMAND="wrk -t$NUM_THREADS -c$NUM_CONNECTIONS -d$TEST_DURATION $URL"
-
-# Define the servers to benchmark
-declare -A servers
-servers["MicroPie"]="uvicorn micro:app --workers 4"
-servers["Starlette"]="uvicorn star:app --workers 4"
-servers["Quart"]="uvicorn qrt:app --workers 4"
-servers["FastAPI"]="uvicorn fast:app --workers 4"
-
-# Output file
-RESULTS_FILE="benchmark_results.txt"
-echo "=== Benchmark Results ===" > "$RESULTS_FILE"
-
-# Function to start server, run benchmark, and stop server
-benchmark_server() {
-    local name="$1"
-    local command="$2"
-
-    echo -e "\n=== Benchmarking $name ==="
-    echo -e "\n=== $name ===" >> "$RESULTS_FILE"
-
-    # Start the server in the background
-    eval "$command &"
-    SERVER_PID=$!
-
-    # Give the server some time to start
-    sleep 3
-
-    # Run wrk test
-    WRK_OUTPUT=$(eval "$WRK_COMMAND")
-
-    # Print and save results
-    echo "$WRK_OUTPUT"
-    echo "$WRK_OUTPUT" >> "$RESULTS_FILE"
-    echo -e "\n========================================\n" >> "$RESULTS_FILE"
-
-    # Stop the server
-    kill $SERVER_PID
-    wait $SERVER_PID 2>/dev/null
-}
-
-# Run benchmarks for each server
-for name in "${!servers[@]}"; do
-    benchmark_server "$name" "${servers[$name]}"
-done
-
-echo -e "\nBenchmarking complete. Results saved in $RESULTS_FILE"
-
diff --git a/examples/hello_world/benchmarks/benchmark_results.txt b/examples/hello_world/benchmarks/benchmark_results.txt
deleted file mode 100644
index e61f94a..0000000
--- a/examples/hello_world/benchmarks/benchmark_results.txt
+++ /dev/null
@@ -1,53 +0,0 @@
-=== Benchmark Results ===
-
-=== Starlette ===
-Running 30s test @ http://127.0.0.1:8000/
-  2 threads and 1000 connections
-  Thread Stats   Avg      Stdev     Max   +/- Stdev
-    Latency   463.73ms   93.44ms 793.29ms   72.98%
-    Req/Sec     1.07k   309.39     1.94k    66.00%
-  64065 requests in 30.09s, 8.87MB read
-Requests/sec:   2129.04
-Transfer/sec:    301.86KB
-
-========================================
-
-
-=== FastAPI ===
-Running 30s test @ http://127.0.0.1:8000/
-  2 threads and 1000 connections
-  Thread Stats   Avg      Stdev     Max   +/- Stdev
-    Latency   622.20ms  104.33ms 953.26ms   73.59%
-    Req/Sec   797.65    216.53     1.48k    69.40%
-  47649 requests in 30.09s, 6.32MB read
-Requests/sec:   1583.67
-Transfer/sec:    215.17KB
-
-========================================
-
-
-=== Quart ===
-Running 30s test @ http://127.0.0.1:8000/
-  2 threads and 1000 connections
-  Thread Stats   Avg      Stdev     Max   +/- Stdev
-    Latency   834.04ms  422.46ms   1.98s    61.02%
-    Req/Sec   597.05    288.80     1.51k    66.55%
-  35581 requests in 30.10s, 4.92MB read
-Requests/sec:   1182.08
-Transfer/sec:    167.45KB
-
-========================================
-
-
-=== MicroPie ===
-Running 30s test @ http://127.0.0.1:8000/
-  2 threads and 1000 connections
-  Thread Stats   Avg      Stdev     Max   +/- Stdev
-    Latency   559.16ms  119.78ms   1.03s    71.57%
-    Req/Sec     0.89k   344.42     1.95k    66.11%
-  53082 requests in 30.09s, 8.26MB read
-Requests/sec:   1763.83
-Transfer/sec:    281.18KB
-
-========================================
-
diff --git a/examples/hello_world/benchmarks/fast.py b/examples/hello_world/benchmarks/fast.py
deleted file mode 100644
index 10cbb09..0000000
--- a/examples/hello_world/benchmarks/fast.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from fastapi import FastAPI
-
-app = FastAPI()
-
[email protected]("/")
-async def index():
-    return "Hello World!"
diff --git a/examples/hello_world/benchmarks/micro.py b/examples/hello_world/benchmarks/micro.py
deleted file mode 100644
index 35aa090..0000000
--- a/examples/hello_world/benchmarks/micro.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from MicroPie import Server
-
-class Root(Server):
-    async def index(self):
-        return f'Hello World!'
-
-app = Root()
diff --git a/examples/hello_world/benchmarks/qrt.py b/examples/hello_world/benchmarks/qrt.py
deleted file mode 100644
index d0f99b1..0000000
--- a/examples/hello_world/benchmarks/qrt.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from quart import Quart
-
-app = Quart(__name__)
-
[email protected]("/")
-async def index():
-    return "Hello World!"
diff --git a/examples/hello_world/benchmarks/star.py b/examples/hello_world/benchmarks/star.py
deleted file mode 100644
index 0634815..0000000
--- a/examples/hello_world/benchmarks/star.py
+++ /dev/null
@@ -1,8 +0,0 @@
-from starlette.applications import Starlette
-from starlette.responses import HTMLResponse
-from starlette.routing import Route
-
-async def index(request):
-    return HTMLResponse(f"Hello World!")
-
-app = Starlette(routes=[Route("/", index)])