This example runs the classic Pystone CPU benchmark behind a FastAPI endpoint on Wasmer Edge.
https://<your-subdomain>.wasmer.app/ (call /?loops=50000 to adjust the workload)
src/main.py contains both the FastAPI app and the benchmark:
- The module defines
app = FastAPI()so Wasmer can loadmain:app. - Pystone logic (records, procedures, and helper functions) is imported from the historical benchmark implementation.
LOOPS = 50000sets the default number of iterations; the/route accepts an optionalloopsquery parameter (capped to twice the default).- The handler calls
pystones(loops)and returns JSON containing the runtime, loop count, and benchmark version. - Running the module directly starts
uvicornon0.0.0.0:8000.
This exposes an easy way to gather performance data from Wasmer Edge.
python -m venv .venv
source .venv/bin/activate
pip install fastapi uvicorn
uvicorn src.main:app --host 0.0.0.0 --port 8000 --reloadThen visit http://127.0.0.1:8000/ or http://127.0.0.1:8000/?loops=100000 to trigger the benchmark.
- Ensure the deployment points to
src.main:app. - Deploy to Wasmer Edge.
- Call
https://<your-subdomain>.wasmer.app/?loops=50000and inspect the JSON benchmark results.