diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-01-27 13:58:10 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-01-27 13:58:10 +0000 |
commit | 6cef9f0fc159de4c9fd708050ec76adb4e74d390 (patch) | |
tree | 81856b3b4da6d18e10516b0be737a157e13f129b /openat/benches/count_processes.rs | |
parent | 9e8dd00da25273fba9f0cafccbde2236e04fb24e (diff) | |
download | pam_usercg_rust-6cef9f0fc159de4c9fd708050ec76adb4e74d390.tar.gz pam_usercg_rust-6cef9f0fc159de4c9fd708050ec76adb4e74d390.tar.xz pam_usercg_rust-6cef9f0fc159de4c9fd708050ec76adb4e74d390.zip |
openat variant
Diffstat (limited to 'openat/benches/count_processes.rs')
-rw-r--r-- | openat/benches/count_processes.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/openat/benches/count_processes.rs b/openat/benches/count_processes.rs new file mode 100644 index 0000000..aa9f856 --- /dev/null +++ b/openat/benches/count_processes.rs @@ -0,0 +1,39 @@ +#![feature(test)] + +extern crate openat; +extern crate test; + + +use std::fs::read_dir; +use std::str::from_utf8; +use std::os::unix::ffi::OsStrExt; +use test::Bencher; + +use openat::Dir; + + +#[bench] +fn procs_stdlib(b: &mut Bencher) { + b.iter(|| { + read_dir("/proc").unwrap().filter(|r| { + r.as_ref().ok() + .and_then(|e| from_utf8(e.file_name().as_bytes()).ok() + // pid is everything that can be parsed as a number + .and_then(|s| s.parse::<u32>().ok())) + .is_some() + }).count() + }); +} + +#[bench] +fn procs_openat(b: &mut Bencher) { + b.iter(|| { + Dir::open("/proc").unwrap().list_dir(".").unwrap().filter(|r| { + r.as_ref().ok() + .and_then(|e| from_utf8(e.file_name().as_bytes()).ok() + // pid is everything that can be parsed as a number + .and_then(|s| s.parse::<u32>().ok())) + .is_some() + }).count() + }); +} |