Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1829 #1872

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collector/runtime-benchmarks/async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "async"
name = "async-bench"
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
version = "0.1.0"
edition = "2021"

Expand Down
24 changes: 10 additions & 14 deletions collector/runtime-benchmarks/async/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<GzDecoder<File>>,x: &mut usize) {
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -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 {
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
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() {
Expand All @@ -36,7 +28,11 @@ fn main() {
// This closure should prepare data that will be needed for the benchmark (if any),
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
// 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()
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
.worker_threads(1)
.enable_all()
.build()
.unwrap();
move || {
rt.block_on(async_operation());
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading