INNER CODE UNIT · Rust
main
cloudflare/workers-rs · benchmark/src/lib.rs:5
async fn main(req: Request, _env: Env, _ctx: Context) -> Result<Response> {
let url = req.url()?;
let path = url.path();
match path {
"/stream" => handle_stream().await,
"/benchmark" => handle_benchmark(&url).await,
_ => Response::error("Not Found", 404),
}
}
/// Streams 1MB of data in chunks
async fn handle_stream() -> Result<Response> {
use futures_util::stream;
// Create 1MB of data (1024 * 1024 bytes)
let chunk_size = 8192; // 8KB chunks
let num_chunks = (1024 * 1024) / chunk_size; // 128 chunks