Created
July 14, 2017 17:24
-
-
Save sethdusek/32e72540c3e660fa4d0c65a482243fd4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #![feature(test)] | |
| extern crate test; | |
| extern crate zerocopy; | |
| use zerocopy::zc::ZeroCopy; | |
| use test::Bencher; | |
| use std::io::prelude::*; | |
| use std::fs::File; | |
| #[bench] | |
| fn zerocopy(b: &mut Bencher) { | |
| let mut src = File::open("/tmp/foo").unwrap(); | |
| let mut dest = File::create("/tmp/foo.txt").unwrap(); | |
| b.iter(|| { | |
| unsafe { src.copy_to_fd(&mut dest).unwrap() }; | |
| src.seek(::std::io::SeekFrom::Start(0)); | |
| }); | |
| std::fs::remove_file("/tmp/foo.txt"); | |
| } | |
| #[bench] | |
| fn default(b: &mut Bencher) { | |
| let mut src = File::open("/tmp/foo").unwrap(); | |
| let mut dest = File::create("/tmp/foo.txt").unwrap(); | |
| let len = src.metadata().unwrap().len() as usize; | |
| b.iter(|| { | |
| ::std::io::copy(&mut src, &mut dest).unwrap(); | |
| src.seek(::std::io::SeekFrom::Start(0)); | |
| }); | |
| std::fs::remove_file("/tmp/foo.txt"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment