Skip to content

Commit eda4c63

Browse files
committed
Add benchmark for File to UnixStream copy
1 parent 0fa9d31 commit eda4c63

File tree

1 file changed

+29
-0
lines changed
  • library/std/src/sys/unix/kernel_copy

1 file changed

+29
-0
lines changed

library/std/src/sys/unix/kernel_copy/tests.rs

+29
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,35 @@ fn bench_file_to_socket_copy(b: &mut test::Bencher) {
118118
});
119119
}
120120

121+
#[bench]
122+
fn bench_file_to_uds_copy(b: &mut test::Bencher) {
123+
const BYTES: usize = 128 * 1024;
124+
let src_path = temp_dir().join("uds-copy-bench-src");
125+
let mut src = OpenOptions::new()
126+
.create(true)
127+
.truncate(true)
128+
.read(true)
129+
.write(true)
130+
.open(src_path)
131+
.unwrap();
132+
src.write(&vec![0u8; BYTES]).unwrap();
133+
134+
let (mut sink, mut sink_drainer) = crate::os::unix::net::UnixStream::pair().unwrap();
135+
136+
crate::thread::spawn(move || {
137+
let mut sink_buf = vec![0u8; 1024 * 1024];
138+
loop {
139+
sink_drainer.read(&mut sink_buf[..]).unwrap();
140+
}
141+
});
142+
143+
b.bytes = BYTES as u64;
144+
b.iter(|| {
145+
src.seek(SeekFrom::Start(0)).unwrap();
146+
assert_eq!(BYTES as u64, io::copy(&mut src, &mut sink).unwrap());
147+
});
148+
}
149+
121150
#[cfg(any(target_os = "linux", target_os = "android"))]
122151
#[bench]
123152
fn bench_socket_pipe_socket_copy(b: &mut test::Bencher) {

0 commit comments

Comments
 (0)