Skip to content
This repository was archived by the owner on May 17, 2026. It is now read-only.

Commit 5450520

Browse files
committed
test: add bench
1 parent a01a966 commit 5450520

4 files changed

Lines changed: 546 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,23 @@ futures-util = { workspace = true, optional = true }
4646
compio = { workspace = true, default-features = false, features = [
4747
"fs",
4848
"net",
49+
"criterion",
4950
] }
5051

51-
tokio = { workspace = true, features = ["rt", "macros", "net", "io-util"] }
52+
tokio = { workspace = true, features = [
53+
"rt",
54+
"macros",
55+
"fs",
56+
"net",
57+
"io-util",
58+
] }
5259
futures-executor = { workspace = true }
5360

61+
criterion = { version = "0.8.2", features = ["async_tokio"] }
62+
futures-util = { workspace = true }
63+
rand = "0.10.1"
64+
tempfile = "3.27.0"
65+
5466
[features]
5567
io-uring = ["compio/io-uring"]
5668
polling = ["compio/polling"]
@@ -61,3 +73,13 @@ enable_log = ["compio-log/enable_log"]
6173
[[test]]
6274
name = "net"
6375
required-features = ["tokio"]
76+
77+
[[bench]]
78+
name = "net"
79+
required-features = ["tokio"]
80+
harness = false
81+
82+
[[bench]]
83+
name = "fs"
84+
required-features = ["tokio"]
85+
harness = false

benches/compat/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use compio_compat::{RuntimeCompat, TokioAdapter};
2+
use criterion::async_executor::AsyncExecutor;
3+
4+
pub struct CompioInTokio {
5+
truntime: tokio::runtime::Runtime,
6+
cruntime: RuntimeCompat<TokioAdapter>,
7+
}
8+
9+
impl Default for CompioInTokio {
10+
fn default() -> Self {
11+
let truntime = tokio::runtime::Builder::new_current_thread()
12+
.enable_all()
13+
.build()
14+
.unwrap();
15+
let cruntime =
16+
RuntimeCompat::<TokioAdapter>::new(compio::runtime::Runtime::new().unwrap()).unwrap();
17+
Self { truntime, cruntime }
18+
}
19+
}
20+
21+
impl AsyncExecutor for CompioInTokio {
22+
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
23+
(&self).block_on(future)
24+
}
25+
}
26+
27+
impl AsyncExecutor for &CompioInTokio {
28+
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
29+
self.truntime.block_on(self.cruntime.execute(future))
30+
}
31+
}

0 commit comments

Comments
 (0)