summaryrefslogtreecommitdiffstats
path: root/third_party/rust/triple_buffer/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /third_party/rust/triple_buffer/benches
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
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);