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

Commit 3ac1494

Browse files
committed
feat(bench): for futures adapter
1 parent d7e608b commit 3ac1494

4 files changed

Lines changed: 95 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ required-features = ["tokio"]
7676

7777
[[bench]]
7878
name = "net"
79-
required-features = ["tokio"]
79+
required-features = ["tokio", "futures"]
8080
harness = false
8181

8282
[[bench]]
8383
name = "fs"
84-
required-features = ["tokio"]
84+
required-features = ["tokio", "futures"]
8585
harness = false
8686

8787
[profile.bench]

benches/compat/mod.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use compio_compat::{RuntimeCompat, TokioAdapter};
1+
use compio_compat::{FuturesAdapter, RuntimeCompat, TokioAdapter};
22
use criterion::async_executor::AsyncExecutor;
33

44
pub struct CompioInTokio {
@@ -30,3 +30,27 @@ impl AsyncExecutor for &CompioInTokio {
3030
self.truntime.block_on(self.cruntime.execute(future))
3131
}
3232
}
33+
34+
pub struct CompioInFutures {
35+
runtime: RuntimeCompat<FuturesAdapter>,
36+
}
37+
38+
impl Default for CompioInFutures {
39+
fn default() -> Self {
40+
let runtime =
41+
RuntimeCompat::<FuturesAdapter>::new(compio::runtime::Runtime::new().unwrap()).unwrap();
42+
Self { runtime }
43+
}
44+
}
45+
46+
impl AsyncExecutor for CompioInFutures {
47+
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
48+
(&self).block_on(future)
49+
}
50+
}
51+
52+
impl AsyncExecutor for &CompioInFutures {
53+
fn block_on<T>(&self, future: impl Future<Output = T>) -> T {
54+
futures_executor::block_on(self.runtime.execute(future))
55+
}
56+
}

benches/fs.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ fn read_compio_in_tokio(b: &mut Bencher, (path, offsets): &(&Path, &[u64])) {
6666
.iter_custom(|iter| read_compio_impl(iter, path, offsets))
6767
}
6868

69+
fn read_compio_in_futures(b: &mut Bencher, (path, offsets): &(&Path, &[u64])) {
70+
let runtime = CompioInFutures::default();
71+
b.to_async(&runtime)
72+
.iter_custom(|iter| read_compio_impl(iter, path, offsets))
73+
}
74+
6975
fn read_all_tokio(b: &mut Bencher, (path, len): &(&Path, u64)) {
7076
let runtime = tokio::runtime::Builder::new_current_thread()
7177
.enable_all()
@@ -116,6 +122,12 @@ fn read_all_compio_in_tokio(b: &mut Bencher, (path, len): &(&Path, u64)) {
116122
.iter_custom(|iter| read_all_compio_impl(iter, path, *len))
117123
}
118124

125+
fn read_all_compio_in_futures(b: &mut Bencher, (path, len): &(&Path, u64)) {
126+
let runtime = CompioInFutures::default();
127+
b.to_async(&runtime)
128+
.iter_custom(|iter| read_all_compio_impl(iter, path, *len))
129+
}
130+
119131
fn read(c: &mut Criterion) {
120132
let mut rng = rng();
121133

@@ -143,6 +155,11 @@ fn read(c: &mut Criterion) {
143155
&(&path, &offsets),
144156
read_compio_in_tokio,
145157
);
158+
group.bench_with_input::<_, _, (&Path, &[u64])>(
159+
"compio-in-futures",
160+
&(&path, &offsets),
161+
read_compio_in_futures,
162+
);
146163

147164
group.finish();
148165

@@ -158,6 +175,12 @@ fn read(c: &mut Criterion) {
158175
&(&path, TOTAL_SIZE),
159176
read_all_compio_in_tokio,
160177
);
178+
group.bench_with_input::<_, _, (&Path, u64)>(
179+
"compio-in-futures",
180+
&(&path, TOTAL_SIZE),
181+
read_all_compio_in_futures,
182+
);
183+
161184
group.finish();
162185
}
163186

@@ -219,6 +242,13 @@ fn write_compio_in_tokio(b: &mut Bencher, (path, offsets, content): &(&Path, &[u
219242
.iter_custom(|iter| write_compio_impl(iter, path, offsets, content.clone()))
220243
}
221244

245+
fn write_compio_in_futures(b: &mut Bencher, (path, offsets, content): &(&Path, &[u64], &[u8])) {
246+
let runtime = CompioInFutures::default();
247+
let content = content.to_vec();
248+
b.to_async(&runtime)
249+
.iter_custom(|iter| write_compio_impl(iter, path, offsets, content.clone()))
250+
}
251+
222252
fn write_all_tokio(b: &mut Bencher, (path, content): &(&Path, &[u8])) {
223253
let runtime = tokio::runtime::Builder::new_current_thread()
224254
.enable_all()
@@ -282,6 +312,13 @@ fn write_all_compio_in_tokio(b: &mut Bencher, (path, content): &(&Path, &[u8]))
282312
.iter_custom(|iter| write_all_compio_impl(iter, path, content.clone()))
283313
}
284314

315+
fn write_all_compio_in_futures(b: &mut Bencher, (path, content): &(&Path, &[u8])) {
316+
let runtime = CompioInFutures::default();
317+
let content = content.to_vec();
318+
b.to_async(&runtime)
319+
.iter_custom(|iter| write_all_compio_impl(iter, path, content.clone()))
320+
}
321+
285322
fn write(c: &mut Criterion) {
286323
const WRITE_FILE_SIZE: u64 = 16;
287324

@@ -329,6 +366,12 @@ fn write(c: &mut Criterion) {
329366
&(&path, &offsets, &single_content),
330367
write_compio_in_tokio,
331368
);
369+
group.bench_with_input::<_, _, (&Path, &[u64], &[u8])>(
370+
"compio-in-futures",
371+
&(&path, &offsets, &single_content),
372+
write_compio_in_futures,
373+
);
374+
332375
group.finish();
333376

334377
let mut group = c.benchmark_group("write-all");
@@ -341,6 +384,11 @@ fn write(c: &mut Criterion) {
341384
&(&path, &content),
342385
write_all_compio_in_tokio,
343386
);
387+
group.bench_with_input::<_, _, (&Path, &[u8])>(
388+
"compio-in-futures",
389+
&(&path, &content),
390+
write_all_compio_in_futures,
391+
);
344392

345393
group.finish()
346394
}

benches/net.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,18 @@ fn echo_compio_tcp(b: &mut Bencher, content: Vec<u8>) {
121121
.iter_custom(|iter| echo_compio_tcp_impl(iter, content.clone()))
122122
}
123123

124-
fn echo_tokio_compio_tcp(b: &mut Bencher, content: Vec<u8>) {
124+
fn echo_compio_in_tokio_tcp(b: &mut Bencher, content: Vec<u8>) {
125125
let runtime = CompioInTokio::default();
126126
b.to_async(&runtime)
127127
.iter_custom(|iter| echo_compio_tcp_impl(iter, content.clone()))
128128
}
129129

130+
fn echo_compio_in_futures_tcp(b: &mut Bencher, content: Vec<u8>) {
131+
let runtime = CompioInFutures::default();
132+
b.to_async(&runtime)
133+
.iter_custom(|iter| echo_compio_tcp_impl(iter, content.clone()))
134+
}
135+
130136
#[cfg(unix)]
131137
fn echo_tokio_unix(b: &mut Bencher, content: &[u8]) {
132138
use tokio::net::{UnixListener, UnixStream};
@@ -191,6 +197,12 @@ fn echo_compio_in_tokio_unix(b: &mut Bencher, content: Vec<u8>) {
191197
.iter_custom(|iter| echo_compio_unix_impl(iter, content.clone()))
192198
}
193199

200+
fn echo_compio_in_futures_unix(b: &mut Bencher, content: Vec<u8>) {
201+
let runtime = CompioInFutures::default();
202+
b.to_async(&runtime)
203+
.iter_custom(|iter| echo_compio_unix_impl(iter, content.clone()))
204+
}
205+
194206
fn echo(c: &mut Criterion) {
195207
let mut rng = rng();
196208

@@ -203,7 +215,10 @@ fn echo(c: &mut Criterion) {
203215
group.bench_function("tokio-tcp", |b| echo_tokio_tcp(b, &content));
204216
group.bench_function("compio-tcp", |b| echo_compio_tcp(b, content.clone()));
205217
group.bench_function("compio-in-tokio-tcp", |b| {
206-
echo_tokio_compio_tcp(b, content.clone())
218+
echo_compio_in_tokio_tcp(b, content.clone())
219+
});
220+
group.bench_function("compio-in-futures-tcp", |b| {
221+
echo_compio_in_futures_tcp(b, content.clone())
207222
});
208223

209224
#[cfg(unix)]
@@ -212,6 +227,9 @@ fn echo(c: &mut Criterion) {
212227
group.bench_function("compio-in-tokio-unix", |b| {
213228
echo_compio_in_tokio_unix(b, content.clone())
214229
});
230+
group.bench_function("compio-in-futures-unix", |b| {
231+
echo_compio_in_futures_unix(b, content.clone())
232+
});
215233

216234
group.finish();
217235
}

0 commit comments

Comments
 (0)