Skip to content

Commit f5ec740

Browse files
committed
resolve the problems
1 parent 72daef0 commit f5ec740

File tree

5 files changed

+49
-84
lines changed

5 files changed

+49
-84
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "asynctest"
2+
name = "async"
33
version = "0.1.0"
44
edition = "2021"
55

@@ -8,5 +8,6 @@ edition = "2021"
88
[dependencies]
99
benchlib = { path = "../../benchlib" }
1010
tokio = { version = "1.0", features = ["full"] }
11+
flate2 = "1"
1112

1213
[workspace]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use benchlib::benchmark::run_benchmark_group;
2+
use std::time::Instant;
3+
use tokio::runtime::Runtime;
4+
use std::fs::File;
5+
use std::io::{self, BufRead, BufReader};
6+
use flate2::read::GzDecoder;
7+
8+
async fn total_char_count(reader: BufReader<GzDecoder<File>>,x: &mut usize) {
9+
for line in reader.lines() {
10+
*x += line_char_count(line.expect("invalid character")).await;
11+
}
12+
}
13+
14+
async fn line_char_count(line: String) -> usize {
15+
let line_count = line.chars().count();
16+
line_count
17+
}
18+
19+
async fn async_operation() -> (usize, u128) {
20+
let start_time = Instant::now();
21+
22+
let file = File::open("./collector/runtime-benchmarks/data/sherlock.txt.gz").expect("can't read a file");
23+
let decoder = GzDecoder::new(file);
24+
let reader2 = BufReader::new(decoder);
25+
let mut total_char = 0;
26+
total_char_count(reader2, &mut total_char).await;
27+
28+
let end_time = Instant::now();
29+
let duration = end_time - start_time;
30+
(total_char,duration.as_millis())
31+
}
32+
33+
fn main() {
34+
run_benchmark_group(|group| {
35+
group.register_benchmark("Async", || {
36+
// This closure should prepare data that will be needed for the benchmark (if any),
37+
// and then return a closure that will actually be benchmarked/profiled.
38+
// Create a Tokio runtime
39+
let rt = Runtime::new().unwrap();
40+
move || {
41+
rt.block_on(async_operation());
42+
}
43+
});
44+
});
45+
}
46+
47+

collector/runtime-benchmarks/asynctest/src/main.rs

-50
This file was deleted.

collector/runtime-benchmarks/asynctest/src/poem.txt

-24
This file was deleted.

collector/runtime-benchmarks/asynctest/src/poem2.txt

-9
This file was deleted.

0 commit comments

Comments
 (0)