summaryrefslogtreecommitdiffstats
path: root/third_party/rust/constant_time_eq/benches
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/constant_time_eq/benches
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.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/constant_time_eq/benches')
-rw-r--r--third_party/rust/constant_time_eq/benches/bench.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/third_party/rust/constant_time_eq/benches/bench.rs b/third_party/rust/constant_time_eq/benches/bench.rs
new file mode 100644
index 0000000000..4b3b790a5d
--- /dev/null
+++ b/third_party/rust/constant_time_eq/benches/bench.rs
@@ -0,0 +1,29 @@
+#![feature(test)]
+
+extern crate constant_time_eq;
+extern crate test;
+
+use constant_time_eq::constant_time_eq;
+use test::{Bencher, black_box};
+
+fn bench(b: &mut Bencher, left: &[u8], right: &[u8]) {
+ b.bytes = (left.len() + right.len()) as u64;
+ b.iter(|| {
+ constant_time_eq(black_box(left), black_box(right))
+ })
+}
+
+#[bench]
+fn bench_16(b: &mut Bencher) {
+ bench(b, &[0; 16], &[0; 16])
+}
+
+#[bench]
+fn bench_4096(b: &mut Bencher) {
+ bench(b, &[0; 4096], &[0; 4096])
+}
+
+#[bench]
+fn bench_65536(b: &mut Bencher) {
+ bench(b, &[0; 65536], &[0; 65536])
+}