pkolaczk / async-runtimes-benchmarks

103 stars 34 forks source link

Rust code missing #9

Open git001 opened 1 year ago

git001 commented 1 year ago

Please can you add also the used rust code, thank you

zhijia2 commented 1 year ago

+1

himyjan commented 1 year ago
use std::thread;
use std::time::Duration;

fn main() {
    let num_threads = 100000;
    let mut handles = Vec::new();
    for _ in 0..num_threads {
        let handle = thread::spawn(|| {
            thread::sleep(Duration::from_secs(10));
        });
        handles.push(handle);
    }
    for handle in handles {
        handle.join().unwrap();
    }
}
use tokio::time;
use tokio::task;
use std::time::Duration;

#[tokio::main]
async fn main() {
    let num_tasks = 100000;
    let mut tasks = Vec::new();
    for _ in 0..num_tasks {
        tasks.push(task::spawn(async {
            task::sleep(Duration::from_secs(10)).await;
        }));
    }
    for task in tasks {
        task.await.unwrap();
    }
}
use async_std::task;
use std::time::Duration;

#[async_std::main]
async fn main() {
    let num_tasks = 100000;
    let mut tasks = Vec::new();
    for _ in 0..num_tasks {
        tasks.push(task::spawn(async {
            task::sleep(Duration::from_secs(10)).await;
        }));
    }
    for task in tasks {
        task.await.unwrap();
    }
}