summaryrefslogtreecommitdiffstats
path: root/third_party/rust/triple_buffer/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/triple_buffer/benches
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/triple_buffer/benches')
-rw-r--r--third_party/rust/triple_buffer/benches/benchmarks.rs80
1 files changed, 80 insertions, 0 deletions
diff --git a/third_party/rust/triple_buffer/benches/benchmarks.rs b/third_party/rust/triple_buffer/benches/benchmarks.rs
new file mode 100644
index 0000000000..c97d1db19e
--- /dev/null
+++ b/third_party/rust/triple_buffer/benches/benchmarks.rs
@@ -0,0 +1,80 @@
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use triple_buffer::TripleBuffer;
+
+pub fn benchmark(c: &mut Criterion) {
+ let (mut input, mut output) = TripleBuffer::<u8>::default().split();
+
+ {
+ let mut uncontended = c.benchmark_group("uncontended");
+ uncontended.bench_function("read output", |b| b.iter(|| *output.output_buffer()));
+ uncontended.bench_function("clean update", |b| {
+ b.iter(|| {
+ output.update();
+ })
+ });
+ uncontended.bench_function("clean receive", |b| b.iter(|| *output.read()));
+ uncontended.bench_function("write input", |b| {
+ b.iter(|| {
+ *input.input_buffer() = black_box(0);
+ })
+ });
+ uncontended.bench_function("publish", |b| {
+ b.iter(|| {
+ input.publish();
+ })
+ });
+ uncontended.bench_function("send", |b| b.iter(|| input.write(black_box(0))));
+ uncontended.bench_function("publish + dirty update", |b| {
+ b.iter(|| {
+ input.publish();
+ output.update();
+ })
+ });
+ uncontended.bench_function("transmit", |b| {
+ b.iter(|| {
+ input.write(black_box(0));
+ *output.read()
+ })
+ });
+ }
+
+ {
+ let mut read_contended = c.benchmark_group("read contention");
+ testbench::run_under_contention(
+ || black_box(*output.read()),
+ || {
+ read_contended.bench_function("write input", |b| {
+ b.iter(|| {
+ *input.input_buffer() = black_box(0);
+ })
+ });
+ read_contended.bench_function("publish", |b| {
+ b.iter(|| {
+ input.publish();
+ })
+ });
+ read_contended.bench_function("send", |b| b.iter(|| input.write(black_box(0))));
+ },
+ );
+ }
+
+ {
+ let mut write_contended = c.benchmark_group("write contention");
+ testbench::run_under_contention(
+ || input.write(black_box(0)),
+ || {
+ write_contended
+ .bench_function("read output", |b| b.iter(|| *output.output_buffer()));
+ write_contended.bench_function("update", |b| {
+ b.iter(|| {
+ output.update();
+ })
+ });
+ write_contended.bench_function("receive", |b| b.iter(|| *output.read()));
+ },
+ );
+ }
+}
+
+criterion_group!(benches, benchmark);
+criterion_main!(benches);