From 51b79823914343b168458cb0c482327204d98ed1 Mon Sep 17 00:00:00 2001 From: Daksh Kaushik Date: Tue, 26 Mar 2024 00:07:26 +0530 Subject: [PATCH] "resolved the comments" --- collector/runtime-benchmarks/async/Cargo.toml | 2 +- .../runtime-benchmarks/async/src/main.rs | 24 ++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/collector/runtime-benchmarks/async/Cargo.toml b/collector/runtime-benchmarks/async/Cargo.toml index ff49a15f4..a31d4e175 100644 --- a/collector/runtime-benchmarks/async/Cargo.toml +++ b/collector/runtime-benchmarks/async/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "async" +name = "async-bench" version = "0.1.0" edition = "2021" diff --git a/collector/runtime-benchmarks/async/src/main.rs b/collector/runtime-benchmarks/async/src/main.rs index 22bfea038..84624d2ea 100644 --- a/collector/runtime-benchmarks/async/src/main.rs +++ b/collector/runtime-benchmarks/async/src/main.rs @@ -1,8 +1,7 @@ use benchlib::benchmark::run_benchmark_group; -use std::time::Instant; -use tokio::runtime::Runtime; +use tokio::runtime::Builder; use std::fs::File; -use std::io::{self, BufRead, BufReader}; +use std::io::{BufRead, BufReader}; use flate2::read::GzDecoder; async fn total_char_count(reader: BufReader>,x: &mut usize) { @@ -16,18 +15,11 @@ async fn line_char_count(line: String) -> usize { line_count } -async fn async_operation() -> (usize, u128) { - let start_time = Instant::now(); - - let file = File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file"); - let decoder = GzDecoder::new(file); - let reader2 = BufReader::new(decoder); +async fn async_operation() -> usize { + let reader2 = BufReader::new(GzDecoder::new(File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file"))); let mut total_char = 0; total_char_count(reader2, &mut total_char).await; - - let end_time = Instant::now(); - let duration = end_time - start_time; - (total_char,duration.as_millis()) + total_char } fn main() { @@ -36,7 +28,11 @@ fn main() { // This closure should prepare data that will be needed for the benchmark (if any), // and then return a closure that will actually be benchmarked/profiled. // Create a Tokio runtime - let rt = Runtime::new().unwrap(); + let rt = Builder::new_multi_thread() + .worker_threads(1) + .enable_all() + .build() + .unwrap(); move || { rt.block_on(async_operation()); }