diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/mio/benches | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/mio/benches')
-rw-r--r-- | third_party/rust/mio/benches/bench_poll.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/third_party/rust/mio/benches/bench_poll.rs b/third_party/rust/mio/benches/bench_poll.rs new file mode 100644 index 0000000000..6b25b22d40 --- /dev/null +++ b/third_party/rust/mio/benches/bench_poll.rs @@ -0,0 +1,53 @@ +#![feature(test)] +#![allow(deprecated)] + +extern crate mio; +extern crate test; + +use mio::*; +use test::Bencher; +use std::sync::Arc; +use std::thread; + +#[bench] +fn bench_poll(bench: &mut Bencher) { + const NUM: usize = 10_000; + const THREADS: usize = 4; + + let poll = Poll::new().unwrap(); + let mut events = Events::with_capacity(1024); + + let mut registrations = vec![]; + let mut set_readiness = vec![]; + + for i in 0..NUM { + let (r, s) = Registration::new( + &poll, + Token(i), + Ready::readable(), + PollOpt::edge()); + + registrations.push(r); + set_readiness.push(s); + } + + let set_readiness = Arc::new(set_readiness); + + bench.iter(move || { + for mut i in 0..THREADS { + let set_readiness = set_readiness.clone(); + thread::spawn(move || { + while i < NUM { + set_readiness[i].set_readiness(Ready::readable()).unwrap(); + i += THREADS; + } + }); + } + + let mut n = 0; + + while n < NUM { + n += poll.poll(&mut events, None).unwrap(); + } + }) +} |