help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
rust-web-server
/
benches
RSK World
rust-web-server
Rust Web Server - High-Performance Async Web Server + WebSocket Support + JWT Authentication + File Upload + Memory Safety + Educational Design
benches
  • server_benchmark.rs3.4 KB
server_benchmark.rs
benches/server_benchmark.rs
Raw Download
Find: Go to:
/*
 * Server Performance Benchmarks - Rust Web Server
 *
 * Created by RSK World (https://rskworld.in)
 * Founder: Molla Samser
 * Designer & Tester: Rima Khatun
 *
 * Contact:
 * - Email: hello@rskworld.in, support@rskworld.in
 * - Phone: +91 93305 39277
 * - Address: Nutanhat, Mongolkote, Purba Burdwan, West Bengal, India, 713147
 *
 * © 2026 RSK World. All rights reserved.
 * Content used for educational purposes only.
 */

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use hyper::{Body, Method, Request, Uri};
use std::path::PathBuf;
use tokio::runtime::Runtime;

use rust_web_server::config::ServerConfig;
use rust_web_server::handlers::SharedState;
use rust_web_server::static_files::StaticFileHandler;

fn bench_request_parsing(c: &mut Criterion) {
    c.bench_function("parse_request_uri", |b| {
        b.iter(|| {
            let uri = black_box(Uri::from_static("http://localhost:8080/api/info"));
            let _path = uri.path();
            let _query = uri.query();
        });
    });
}

fn bench_config_creation(c: &mut Criterion) {
    c.bench_function("server_config_creation", |b| {
        b.iter(|| {
            let config = ServerConfig::new(
                black_box("127.0.0.1".to_string()),
                black_box(8080),
                black_box(PathBuf::from("static")),
                black_box(4),
            );
            black_box(config);
        });
    });
}

fn bench_static_file_handler(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();
    let static_handler = rt.block_on(async {
        StaticFileHandler::new(PathBuf::from("static"))
    });

    c.bench_function("static_file_handler_creation", |b| {
        b.iter(|| {
            let handler = StaticFileHandler::new(black_box(PathBuf::from("static")));
            black_box(handler);
        });
    });
}

fn bench_shared_state(c: &mut Criterion) {
    let rt = Runtime::new().unwrap();

    c.bench_function("shared_state_creation", |b| {
        b.iter(|| {
            rt.block_on(async {
                let static_handler = StaticFileHandler::new(PathBuf::from("static"));
                let state = SharedState::new(static_handler);
                black_box(state);
            });
        });
    });
}

fn bench_json_serialization(c: &mut Criterion) {
    use serde_json;
    use std::collections::HashMap;

    let test_data = {
        let mut map = HashMap::new();
        map.insert("message", "Hello, World!");
        map.insert("timestamp", "2026-01-23T10:00:00Z");
        map.insert("method", "GET");
        map.insert("path", "/api/test");
        map
    };

    c.bench_function("json_serialization", |b| {
        b.iter(|| {
            let json = serde_json::to_string(black_box(&test_data)).unwrap();
            black_box(json);
        });
    });

    let json_str = r#"{"message":"Hello, World!","timestamp":"2026-01-23T10:00:00Z","method":"GET","path":"/api/test"}"#;

    c.bench_function("json_deserialization", |b| {
        b.iter(|| {
            let data: HashMap<String, String> = serde_json::from_str(black_box(json_str)).unwrap();
            black_box(data);
        });
    });
}

criterion_group!(
    benches,
    bench_request_parsing,
    bench_config_creation,
    bench_static_file_handler,
    bench_shared_state,
    bench_json_serialization
);
criterion_main!(benches);
116 lines•3.4 KB
rust

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer