summaryrefslogtreecommitdiffstats
path: root/vendor/bytecount/benches/bench.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/bytecount/benches/bench.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/bytecount/benches/bench.rs')
-rw-r--r--vendor/bytecount/benches/bench.rs69
1 files changed, 38 insertions, 31 deletions
diff --git a/vendor/bytecount/benches/bench.rs b/vendor/bytecount/benches/bench.rs
index 85d04dbb4..2e091fccc 100644
--- a/vendor/bytecount/benches/bench.rs
+++ b/vendor/bytecount/benches/bench.rs
@@ -1,17 +1,14 @@
#[macro_use]
extern crate criterion;
-extern crate rand;
extern crate bytecount;
+extern crate rand;
+use criterion::{Bencher, BenchmarkId, Criterion};
+use rand::RngCore;
use std::env;
use std::time::Duration;
-use rand::RngCore;
-use criterion::{Bencher, Criterion, ParameterizedBenchmark};
-use bytecount::{
- count, naive_count, naive_count_32,
- num_chars, naive_num_chars,
-};
+use bytecount::{count, naive_count, naive_count_32, naive_num_chars, num_chars};
fn random_bytes(len: usize) -> Vec<u8> {
let mut result = vec![0; len];
@@ -19,25 +16,29 @@ fn random_bytes(len: usize) -> Vec<u8> {
result
}
-static COUNTS : &[usize] = &[0, 10, 20, 30, 40, 50, 60, 70, 80, 90,
- 100, 120, 140, 170, 210, 250, 300, 400, 500, 600, 700, 800, 900,
- 1000, 1_000, 1_200, 1_400, 1_700, 2_100, 2_500, 3_000, 4_000,
- 5_000, 6_000, 7_000, 8_000, 9_000, 10_000, 12_000, 14_000, 17_000,
- 21_000, 25_000, 30_000, 100_000, 1_000_000];
+static COUNTS: &[usize] = &[
+ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 170, 210, 250, 300, 400, 500, 600, 700,
+ 800, 900, 1_000, 1_200, 1_400, 1_700, 2_100, 2_500, 3_000, 4_000, 5_000, 6_000, 7_000, 8_000,
+ 9_000, 10_000, 12_000, 14_000, 17_000, 21_000, 25_000, 30_000, 100_000, 1_000_000,
+];
fn get_counts() -> Vec<usize> {
- env::var("COUNTS").map(
- |s| s.split(',').map(
- |n| str::parse::<usize>(n).unwrap()).collect())
+ env::var("COUNTS")
+ .map(|s| {
+ s.split(',')
+ .map(|n| str::parse::<usize>(n).unwrap())
+ .collect()
+ })
.unwrap_or(COUNTS.to_owned())
}
fn get_config() -> Criterion {
if env::var("CI").is_ok() {
- Criterion::default().nresamples(5_000)
- .without_plots()
- .measurement_time(Duration::new(2, 0))
- .warm_up_time(Duration::new(1, 0))
+ Criterion::default()
+ .nresamples(5_000)
+ .without_plots()
+ .measurement_time(Duration::new(2, 0))
+ .warm_up_time(Duration::new(1, 0))
} else {
Criterion::default()
}
@@ -45,37 +46,43 @@ fn get_config() -> Criterion {
fn bench_counts(criterion: &mut Criterion) {
fn naive(b: &mut Bencher, s: &usize) {
- let haystack = random_bytes(*s);
+ let haystack = random_bytes(*s);
b.iter(|| naive_count(&haystack, 10))
}
fn naive_32(b: &mut Bencher, s: &usize) {
- let haystack = random_bytes(*s);
+ let haystack = random_bytes(*s);
b.iter(|| naive_count_32(&haystack, 10))
}
fn hyper(b: &mut Bencher, s: &usize) {
- let haystack = random_bytes(*s);
+ let haystack = random_bytes(*s);
b.iter(|| count(&haystack, 10))
}
let counts = get_counts();
- criterion.bench("counts",
- ParameterizedBenchmark::new("naive", naive, counts)
- .with_function("naive_32", naive_32)
- .with_function("hyper", hyper));
+ let mut group = criterion.benchmark_group("counts");
+ for count in counts {
+ group.throughput(criterion::Throughput::Bytes(count as u64));
+ group.bench_with_input(BenchmarkId::new("naive", count), &count, naive);
+ group.bench_with_input(BenchmarkId::new("naive_32", count), &count, naive_32);
+ group.bench_with_input(BenchmarkId::new("hyper", count), &count, hyper);
+ }
}
fn bench_num_chars(criterion: &mut Criterion) {
fn naive(b: &mut Bencher, s: &usize) {
- let haystack = random_bytes(*s);
+ let haystack = random_bytes(*s);
b.iter(|| naive_num_chars(&haystack))
}
fn hyper(b: &mut Bencher, s: &usize) {
- let haystack = random_bytes(*s);
+ let haystack = random_bytes(*s);
b.iter(|| num_chars(&haystack))
}
let counts = get_counts();
- criterion.bench("num_chars",
- ParameterizedBenchmark::new("naive", naive, counts)
- .with_function("hyper", hyper));
+ let mut group = criterion.benchmark_group("num_chars");
+ for count in counts {
+ group.throughput(criterion::Throughput::Bytes(count as u64));
+ group.bench_with_input(BenchmarkId::new("naive", count), &count, naive);
+ group.bench_with_input(BenchmarkId::new("hyper", count), &count, hyper);
+ }
}
criterion_group!(name = count_bench; config = get_config(); targets = bench_counts);