diff options
| author | Nicolas Koch <nioko1337@googlemail.com> | 2020-12-01 14:44:40 +0100 |
|---|---|---|
| committer | Nicolas Koch <nioko1337@googlemail.com> | 2020-12-01 14:44:40 +0100 |
| commit | eda4c63fdcfe4717ade45333b90bd1568ebcc949 (patch) | |
| tree | d3552973f5324d26236b88e0fc2d06ef03ca27e9 | |
| parent | 0fa9d31c41cfa5f60dbce1204104eb8d8261be5f (diff) | |
| download | rust-eda4c63fdcfe4717ade45333b90bd1568ebcc949.tar.gz rust-eda4c63fdcfe4717ade45333b90bd1568ebcc949.zip | |
Add benchmark for File to UnixStream copy
| -rw-r--r-- | library/std/src/sys/unix/kernel_copy/tests.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/kernel_copy/tests.rs b/library/std/src/sys/unix/kernel_copy/tests.rs index 21b121c26ff..554ebd94022 100644 --- a/library/std/src/sys/unix/kernel_copy/tests.rs +++ b/library/std/src/sys/unix/kernel_copy/tests.rs @@ -118,6 +118,35 @@ fn bench_file_to_socket_copy(b: &mut test::Bencher) { }); } +#[bench] +fn bench_file_to_uds_copy(b: &mut test::Bencher) { + const BYTES: usize = 128 * 1024; + let src_path = temp_dir().join("uds-copy-bench-src"); + let mut src = OpenOptions::new() + .create(true) + .truncate(true) + .read(true) + .write(true) + .open(src_path) + .unwrap(); + src.write(&vec![0u8; BYTES]).unwrap(); + + let (mut sink, mut sink_drainer) = crate::os::unix::net::UnixStream::pair().unwrap(); + + crate::thread::spawn(move || { + let mut sink_buf = vec![0u8; 1024 * 1024]; + loop { + sink_drainer.read(&mut sink_buf[..]).unwrap(); + } + }); + + b.bytes = BYTES as u64; + b.iter(|| { + src.seek(SeekFrom::Start(0)).unwrap(); + assert_eq!(BYTES as u64, io::copy(&mut src, &mut sink).unwrap()); + }); +} + #[cfg(any(target_os = "linux", target_os = "android"))] #[bench] fn bench_socket_pipe_socket_copy(b: &mut test::Bencher) { |
