-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
micro-optimization: reuse same cursor over and over
- Loading branch information
Showing
2 changed files
with
36 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,36 @@ | ||
#![feature(async_await)] | ||
|
||
#[macro_use] | ||
extern crate criterion; | ||
use criterion::*; | ||
|
||
use criterion::Criterion; | ||
use futures::executor::ThreadPool; | ||
use futures::prelude::*; | ||
use std::io; | ||
fn benchmark(c: &mut Criterion) { | ||
c.bench_function("write 100 1K chunks", |b| { | ||
use futures::executor::ThreadPool; | ||
use futures::prelude::*; | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
c.bench_function("pipe_read_write", |b| { | ||
let mut pool = ThreadPool::new().unwrap(); | ||
let data = [1; 0x1000]; | ||
|
||
b.iter(|| { | ||
let (mut reader, mut writer) = sluice::pipe::pipe(); | ||
|
||
let producer = async { | ||
for _ in 0..0x10 { | ||
writer.write_all(&data).await.unwrap(); | ||
} | ||
writer.close().await.unwrap(); | ||
}; | ||
|
||
let consumer = async { | ||
let mut sink = io::sink(); | ||
reader.copy_into(&mut sink).await.unwrap(); | ||
}; | ||
|
||
pool.run(future::join(producer, consumer)); | ||
}) | ||
let data = [1; 1024]; | ||
|
||
b.iter_batched( | ||
sluice::pipe::pipe, | ||
|(mut reader, mut writer)| { | ||
let producer = async { | ||
for _ in 0..100 { | ||
writer.write_all(&data).await.unwrap(); | ||
} | ||
writer.close().await.unwrap(); | ||
}; | ||
|
||
let consumer = async { | ||
let mut sink = std::io::sink(); | ||
reader.copy_into(&mut sink).await.unwrap(); | ||
}; | ||
|
||
pool.run(future::join(producer, consumer)); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_group!(benches, benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters