Skip to content

Commit

Permalink
resolve the problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh-10 committed Mar 24, 2024
1 parent 72daef0 commit f5ec740
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "asynctest"
name = "async"
version = "0.1.0"
edition = "2021"

Expand All @@ -8,5 +8,6 @@ edition = "2021"
[dependencies]
benchlib = { path = "../../benchlib" }
tokio = { version = "1.0", features = ["full"] }
flate2 = "1"

[workspace]
47 changes: 47 additions & 0 deletions collector/runtime-benchmarks/async/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use benchlib::benchmark::run_benchmark_group;
use std::time::Instant;
use tokio::runtime::Runtime;
use std::fs::File;
use std::io::{self, BufRead, BufReader};
use flate2::read::GzDecoder;

async fn total_char_count(reader: BufReader<GzDecoder<File>>,x: &mut usize) {
for line in reader.lines() {
*x += line_char_count(line.expect("invalid character")).await;
}
}

async fn line_char_count(line: String) -> usize {
let line_count = line.chars().count();
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);
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())
}

fn main() {
run_benchmark_group(|group| {
group.register_benchmark("Async", || {
// 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();
move || {
rt.block_on(async_operation());
}
});
});
}


50 changes: 0 additions & 50 deletions collector/runtime-benchmarks/asynctest/src/main.rs

This file was deleted.

24 changes: 0 additions & 24 deletions collector/runtime-benchmarks/asynctest/src/poem.txt

This file was deleted.

9 changes: 0 additions & 9 deletions collector/runtime-benchmarks/asynctest/src/poem2.txt

This file was deleted.

0 comments on commit f5ec740

Please sign in to comment.