└── benchmrk /benchmrk: -------------------------------------------------------------------------------- 1 | # Concurrency Benchmark Tool 2 | 3 | This project benchmarks the performance of different concurrency patterns in Rust, such as async, multithreading, and message passing. 4 | 5 | ## Installation 6 | To build and run the project: 7 | 8 | ```bash 9 | git clone https://github.com/yourusername/concurrency-benchmark.git 10 | cd concurrency-benchmark 11 | cargo run 12 | 13 | 14 | **Code** (`src/main.rs`): 15 | ```rust 16 | use std::time::Instant; 17 | use tokio::task; 18 | 19 | async fn async_task() { 20 | tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; 21 | } 22 | 23 | fn multithreaded_task() { 24 | let handle = std::thread::spawn(|| { 25 | std::thread::sleep(std::time::Duration::from_millis(500)); 26 | }); 27 | handle.join().unwrap(); 28 | } 29 | 30 | #[tokio::main] 31 | async fn main() { 32 | let start = Instant::now(); 33 | async_task().await; 34 | println!("Async task took: {:?}", start.elapsed()); 35 | 36 | let start = Instant::now(); 37 | multithreaded_task(); 38 | println!("Multithreaded task took: {:?}", start.elapsed()); 39 | } 40 | --------------------------------------------------------------------------------