Skip to content

Commit 3374bcd

Browse files
committed
Added an async runtime benchmark
1 parent b1a9eb1 commit 3374bcd

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "asynctest"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
benchlib = { path = "../../benchlib" }
10+
tokio = { version = "1.0", features = ["full"] }
11+
12+
[workspace]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
7+
async fn read_the_textfile(file_path: &str) -> io::Result<usize> {
8+
let file = File::open(file_path)?;
9+
let reader = BufReader::new(file);
10+
let mut total_characters = 0;
11+
for line in reader.lines() {
12+
let line = line?;
13+
total_characters += line.len();
14+
}
15+
16+
Ok(total_characters)
17+
}
18+
19+
async fn async_operation() {
20+
let f1 = read_the_textfile("./collector/runtime-benchmarks/Async2/src/poem.txt").await.expect("Can't read file");
21+
let f2 = read_the_textfile("./collector/runtime-benchmarks/Async2/src/poem2.txt").await.expect("Can't read file");
22+
let total_char_count =f1+f2;
23+
24+
}
25+
26+
fn main() {
27+
run_benchmark_group(|group| {
28+
group.register_benchmark("Async", || {
29+
// This closure should prepare data that will be needed for the benchmark (if any),
30+
// and then return a closure that will actually be benchmarked/profiled.
31+
32+
// Create a Tokio runtime
33+
let rt = Runtime::new().unwrap();
34+
let start_time = Instant::now();
35+
36+
for _ in 0..1000 {
37+
rt.block_on(async_operation());
38+
}
39+
40+
let end_time = Instant::now();
41+
42+
let duration = end_time - start_time;
43+
move || {
44+
duration
45+
}
46+
});
47+
});
48+
}
49+
50+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
In the realm where code weaves tales bold,
2+
A language emerged, its story untold.
3+
With the hue of iron, sturdy and grand,
4+
Rust stood firm on digital land.
5+
6+
In the hearts of developers, it found its place,
7+
A tool for crafting with elegance and grace.
8+
With syntax refined, like a poet's pen,
9+
It beckons creators, both women and men.
10+
11+
In the crucible of time, it was forged with care,
12+
To conquer challenges, it did dare.
13+
With lifetimes borrowed from legends of old,
14+
Rust marches forth, fearless and bold.
15+
16+
It guards against errors with a vigilant eye,
17+
Through ownership and borrowing, it helps us fly.
18+
No more shall we fear the rust of old,
19+
For Rust, the language, is a sight to behold.
20+
21+
With concurrency, it dances in harmony's tune,
22+
Asynchronous rhythms, like stars 'neath the moon.
23+
In lifetimes and traits, its essence imbued,
24+
A symphony of traits, in harmony renewed.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
O Rust, thou art a masterpiece divine,
2+
In the kingdom of languages, you brightly shine.
3+
With borrow checkers and lifetimes in hand,
4+
You lead us forward, across the digital land.
5+
6+
So let us raise a toast to Rust, our guide,
7+
In its shelter, our dreams shall abide.
8+
For in its embrace, we find our worth,
9+
Rust, the language, the pride of Earth.

0 commit comments

Comments
 (0)