summaryrefslogtreecommitdiffstats
path: root/third_party/rust/adler/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/adler/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/adler/benches')
-rw-r--r--third_party/rust/adler/benches/bench.rs109
1 files changed, 109 insertions, 0 deletions
diff --git a/third_party/rust/adler/benches/bench.rs b/third_party/rust/adler/benches/bench.rs
new file mode 100644
index 0000000000..0969f59483
--- /dev/null
+++ b/third_party/rust/adler/benches/bench.rs
@@ -0,0 +1,109 @@
+extern crate adler;
+extern crate criterion;
+
+use adler::{adler32_slice, Adler32};
+use criterion::{criterion_group, criterion_main, Criterion, Throughput};
+
+fn simple(c: &mut Criterion) {
+ {
+ const SIZE: usize = 100;
+
+ let mut group = c.benchmark_group("simple-100b");
+ group.throughput(Throughput::Bytes(SIZE as u64));
+ group.bench_function("zeroes-100", |bencher| {
+ bencher.iter(|| {
+ adler32_slice(&[0; SIZE]);
+ });
+ });
+ group.bench_function("ones-100", |bencher| {
+ bencher.iter(|| {
+ adler32_slice(&[0xff; SIZE]);
+ });
+ });
+ }
+
+ {
+ const SIZE: usize = 1024;
+
+ let mut group = c.benchmark_group("simple-1k");
+ group.throughput(Throughput::Bytes(SIZE as u64));
+
+ group.bench_function("zeroes-1k", |bencher| {
+ bencher.iter(|| {
+ adler32_slice(&[0; SIZE]);
+ });
+ });
+
+ group.bench_function("ones-1k", |bencher| {
+ bencher.iter(|| {
+ adler32_slice(&[0xff; SIZE]);
+ });
+ });
+ }
+
+ {
+ const SIZE: usize = 1024 * 1024;
+
+ let mut group = c.benchmark_group("simple-1m");
+ group.throughput(Throughput::Bytes(SIZE as u64));
+ group.bench_function("zeroes-1m", |bencher| {
+ bencher.iter(|| {
+ adler32_slice(&[0; SIZE]);
+ });
+ });
+
+ group.bench_function("ones-1m", |bencher| {
+ bencher.iter(|| {
+ adler32_slice(&[0xff; SIZE]);
+ });
+ });
+ }
+}
+
+fn chunked(c: &mut Criterion) {
+ const SIZE: usize = 16 * 1024 * 1024;
+
+ let data = vec![0xAB; SIZE];
+
+ let mut group = c.benchmark_group("chunked-16m");
+ group.throughput(Throughput::Bytes(SIZE as u64));
+ group.bench_function("5552", |bencher| {
+ bencher.iter(|| {
+ let mut h = Adler32::new();
+ for chunk in data.chunks(5552) {
+ h.write_slice(chunk);
+ }
+ h.checksum()
+ });
+ });
+ group.bench_function("8k", |bencher| {
+ bencher.iter(|| {
+ let mut h = Adler32::new();
+ for chunk in data.chunks(8 * 1024) {
+ h.write_slice(chunk);
+ }
+ h.checksum()
+ });
+ });
+ group.bench_function("64k", |bencher| {
+ bencher.iter(|| {
+ let mut h = Adler32::new();
+ for chunk in data.chunks(64 * 1024) {
+ h.write_slice(chunk);
+ }
+ h.checksum()
+ });
+ });
+ group.bench_function("1m", |bencher| {
+ bencher.iter(|| {
+ let mut h = Adler32::new();
+ for chunk in data.chunks(1024 * 1024) {
+ h.write_slice(chunk);
+ }
+ h.checksum()
+ });
+ });
+}
+
+criterion_group!(benches, simple, chunked);
+criterion_main!(benches);