Skip to content

Commit

Permalink
Rust edition 2021 + cargo fmt + cargo upgrade + taplo format
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Mar 15, 2024
1 parent 072352e commit 081785e
Show file tree
Hide file tree
Showing 70 changed files with 1,744 additions and 2,720 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
on:
push:
branches:
- master
- main
pull_request:
branches:
- master
- version-0.4
- main

name: tests
env:
Expand Down
76 changes: 38 additions & 38 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,56 @@ name = "criterion2"
#
# * Update version numbers in the book;
version = "0.5.1"
edition = "2018"
edition = "2021"

description = "Statistics-driven micro-benchmarking library"
homepage = "https://bheisler.github.io/criterion.rs/book/index.html"
repository = "https://github.com/bheisler/criterion.rs"
readme = "README.md"
keywords = ["criterion", "benchmark"]
categories = ["development-tools::profiling"]
license = "Apache-2.0 OR MIT"
exclude = ["book/*"]
homepage = "https://bheisler.github.io/criterion.rs/book/index.html"
repository = "https://github.com/bheisler/criterion.rs"
readme = "README.md"
keywords = ["criterion", "benchmark"]
categories = ["development-tools::profiling"]
license = "Apache-2.0 OR MIT"
exclude = ["book/*"]

[dependencies]
anes = "0.1.4"
once_cell = "1.14"
anes = "0.1.6"
once_cell = "1.19"
criterion-plot = { path = "plot", version = "0.5.0" }
itertools = ">=0.10, <=0.12"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
ciborium = "0.2.0"
clap = { version = "4", default-features = false, features = ["std", "help"] }
walkdir = "2.3"
tinytemplate = "1.1"
cast = "0.3"
num-traits = { version = "0.2", default-features = false, features = ["std"] }
oorandom = "11.1"
regex = { version = "1.5", default-features = false, features = ["std"] }
itertools = ">=0.10, <=0.12"
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
ciborium = "0.2.2"
clap = { version = "4", default-features = false, features = ["std", "help"] }
walkdir = "2.5"
tinytemplate = "1.2"
cast = "0.3"
num-traits = { version = "0.2", default-features = false, features = ["std"] }
oorandom = "11.1"
regex = { version = "1.10", default-features = false, features = ["std"] }

# Optional dependencies
rayon = { version = "1.3", optional = true }
csv = { version = "1.1", optional = true }
rayon = { version = "1.9", optional = true }
csv = { version = "1.3", optional = true }
futures = { version = "0.3", default_features = false, optional = true }
smol = { version = "1.2", default-features = false, optional = true }
tokio = { version = "1.0", default-features = false, features = [
smol = { version = "1.3", default-features = false, optional = true }
tokio = { version = "1.36", default-features = false, features = [
"rt",
], optional = true }
async-std = { version = "1.9", optional = true }
async-std = { version = "1.12", optional = true }

[dependencies.plotters]
version = "^0.3.1"
optional = true
version = "^0.3.5"
optional = true
default-features = false
features = ["svg_backend", "area_series", "line_series"]
features = ["svg_backend", "area_series", "line_series"]

[dev-dependencies]
tempfile = "3.5.0"
approx = "0.5.0"
tempfile = "3.10.1"
approx = "0.5.1"
quickcheck = { version = "1.0", default-features = false }
rand = "0.8"
futures = { version = "0.3", default_features = false, features = ["executor"] }
rand = "0.8"
futures = { version = "0.3", default_features = false, features = ["executor"] }

[badges]
maintenance = { status = "passively-maintained" }
Expand All @@ -83,9 +83,9 @@ async = []
# These features enable built-in support for running async benchmarks on each different async
# runtime.
async_futures = ["futures/executor", "async"]
async_smol = ["smol", "async"]
async_tokio = ["tokio", "async"]
async_std = ["async-std", "async"]
async_smol = ["smol", "async"]
async_tokio = ["tokio", "async"]
async_std = ["async-std", "async"]

# This feature _currently_ does nothing except disable a warning message, but in 0.4.0 it will be
# required in order to have Criterion.rs generate its own plots (as opposed to using cargo-criterion)
Expand All @@ -104,7 +104,7 @@ csv_output = ["csv"]
exclude = ["cargo-criterion"]

[[bench]]
name = "bench_main"
name = "bench_main"
harness = false

[lib]
Expand Down
2 changes: 1 addition & 1 deletion bencher_compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ default = []
name = "bencher_example"
harness = false

[workspace]
[workspace]
37 changes: 15 additions & 22 deletions bencher_compat/benches/bencher_example.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#[macro_use]
extern crate criterion_bencher_compat;

use criterion_bencher_compat::Bencher;

fn a(bench: &mut Bencher) {
bench.iter(|| {
(0..1000).fold(0, |x, y| x + y)
})
}

fn b(bench: &mut Bencher) {
const N: usize = 1024;
bench.iter(|| {
vec![0u8; N]
});

bench.bytes = N as u64;
}

benchmark_group!(benches, a, b);
benchmark_main!(benches);
use criterion_bencher_compat::Bencher;

fn a(bench: &mut Bencher) {
bench.iter(|| (0..1000).fold(0, |x, y| x + y))
}

fn b(bench: &mut Bencher) {
const N: usize = 1024;
bench.iter(|| vec![0u8; N]);

bench.bytes = N as u64;
}

benchmark_group!(benches, a, b);
benchmark_main!(benches);
9 changes: 4 additions & 5 deletions bencher_compat/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
extern crate criterion;

pub use criterion::Criterion;
pub use criterion::black_box;
use criterion::measurement::WallTime;
pub use criterion::Criterion;

/// Stand-in for `bencher::Bencher` which uses Criterion.rs to perform the benchmark instead.
pub struct Bencher<'a, 'b> {
Expand All @@ -12,7 +10,8 @@ pub struct Bencher<'a, 'b> {
impl<'a, 'b> Bencher<'a, 'b> {
/// Callback for benchmark functions to run to perform the benchmark
pub fn iter<T, F>(&mut self, inner: F)
where F: FnMut() -> T
where
F: FnMut() -> T,
{
self.bencher.iter(inner);
}
Expand Down Expand Up @@ -60,4 +59,4 @@ macro_rules! benchmark_main {
($($group_name:path,)+) => {
benchmark_main!($($group_name),+);
};
}
}
2 changes: 1 addition & 1 deletion benches/bench_main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::criterion_main;
use criterion2::criterion_main;

mod benchmarks;

Expand Down
26 changes: 9 additions & 17 deletions benches/benchmarks/async_measurement_overhead.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
use criterion::{async_executor::FuturesExecutor, criterion_group, BatchSize, Criterion};
use criterion2::{async_executor::FuturesExecutor, criterion_group, BatchSize, Criterion};

fn some_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("async overhead");
group.bench_function("iter", |b| b.to_async(FuturesExecutor).iter(|| async { 1 }));
group.bench_function("iter_with_setup", |b| {
b.to_async(FuturesExecutor)
.iter_with_setup(|| (), |_| async { 1 })
b.to_async(FuturesExecutor).iter_with_setup(|| (), |_| async { 1 })
});
group.bench_function("iter_with_large_setup", |b| {
b.to_async(FuturesExecutor)
.iter_with_large_setup(|| (), |_| async { 1 })
b.to_async(FuturesExecutor).iter_with_large_setup(|| (), |_| async { 1 })
});
group.bench_function("iter_with_large_drop", |b| {
b.to_async(FuturesExecutor)
.iter_with_large_drop(|| async { 1 })
b.to_async(FuturesExecutor).iter_with_large_drop(|| async { 1 })
});
group.bench_function("iter_batched_small_input", |b| {
b.to_async(FuturesExecutor)
.iter_batched(|| (), |_| async { 1 }, BatchSize::SmallInput)
b.to_async(FuturesExecutor).iter_batched(|| (), |_| async { 1 }, BatchSize::SmallInput)
});
group.bench_function("iter_batched_large_input", |b| {
b.to_async(FuturesExecutor)
.iter_batched(|| (), |_| async { 1 }, BatchSize::LargeInput)
b.to_async(FuturesExecutor).iter_batched(|| (), |_| async { 1 }, BatchSize::LargeInput)
});
group.bench_function("iter_batched_per_iteration", |b| {
b.to_async(FuturesExecutor)
.iter_batched(|| (), |_| async { 1 }, BatchSize::PerIteration)
b.to_async(FuturesExecutor).iter_batched(|| (), |_| async { 1 }, BatchSize::PerIteration)
});
group.bench_function("iter_batched_ref_small_input", |b| {
b.to_async(FuturesExecutor)
.iter_batched_ref(|| (), |_| async { 1 }, BatchSize::SmallInput)
b.to_async(FuturesExecutor).iter_batched_ref(|| (), |_| async { 1 }, BatchSize::SmallInput)
});
group.bench_function("iter_batched_ref_large_input", |b| {
b.to_async(FuturesExecutor)
.iter_batched_ref(|| (), |_| async { 1 }, BatchSize::LargeInput)
b.to_async(FuturesExecutor).iter_batched_ref(|| (), |_| async { 1 }, BatchSize::LargeInput)
});
group.bench_function("iter_batched_ref_per_iteration", |b| {
b.to_async(FuturesExecutor).iter_batched_ref(
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/compare_functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, BenchmarkId, Criterion};
use criterion2::{criterion_group, BenchmarkId, Criterion};

fn fibonacci_slow(n: u64) -> u64 {
match n {
Expand Down
9 changes: 4 additions & 5 deletions benches/benchmarks/custom_measurement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{
use criterion2::{
black_box, criterion_group,
measurement::{Measurement, ValueFormatter},
Criterion, Throughput,
Expand All @@ -17,10 +17,9 @@ impl ValueFormatter for HalfSecFormatter {
Throughput::Bytes(bytes) | Throughput::BytesDecimal(bytes) => {
format!("{} b/s/2", (bytes as f64) / (value * 2f64 * 10f64.powi(-9)))
}
Throughput::Elements(elems) => format!(
"{} elem/s/2",
(elems as f64) / (value * 2f64 * 10f64.powi(-9))
),
Throughput::Elements(elems) => {
format!("{} elem/s/2", (elems as f64) / (value * 2f64 * 10f64.powi(-9)))
}
}
}

Expand Down
18 changes: 5 additions & 13 deletions benches/benchmarks/external_process.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, Criterion};
use criterion2::{criterion_group, Criterion};
use std::{
io::{BufRead, BufReader, Write},
process::{Command, Stdio},
Expand All @@ -8,9 +8,7 @@ use std::{

fn create_command() -> Command {
let mut command = Command::new("python3");
command
.arg("benches/benchmarks/external_process.py")
.arg("10");
command.arg("benches/benchmarks/external_process.py").arg("10");
command
}

Expand All @@ -29,21 +27,15 @@ fn python_fibonacci(c: &mut Criterion) {
.spawn()
.expect("Unable to start python process");

let mut stdin = process
.stdin
.expect("Unable to get stdin for child process");
let stdout = process
.stdout
.expect("Unable to get stdout for child process");
let mut stdin = process.stdin.expect("Unable to get stdin for child process");
let stdout = process.stdout.expect("Unable to get stdout for child process");
let mut stdout = BufReader::new(stdout);
c.bench_function("fibonacci-python", |b| {
b.iter_custom(|iters| {
writeln!(stdin, "{}", iters)
.expect("Unable to send iteration count to child process");
let mut line = String::new();
stdout
.read_line(&mut line)
.expect("Unable to read time from child process");
stdout.read_line(&mut line).expect("Unable to read time from child process");
let nanoseconds: u64 =
u64::from_str(line.trim()).expect("Unable to parse time from child process");
Duration::from_nanos(nanoseconds)
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/iter_with_large_drop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, Criterion, Throughput};
use criterion2::{criterion_group, Criterion, Throughput};
use std::time::Duration;

const SIZE: usize = 1024 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/iter_with_large_setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, BatchSize, Criterion, Throughput};
use criterion2::{criterion_group, BatchSize, Criterion, Throughput};
use std::time::Duration;

const SIZE: usize = 1024 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/iter_with_setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, Criterion};
use criterion2::{criterion_group, Criterion};

const SIZE: usize = 1024 * 1024;

Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/measurement_overhead.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use criterion::{criterion_group, BatchSize, Criterion};
use criterion2::{criterion_group, BatchSize, Criterion};

fn some_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("overhead");
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmarks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod async_measurement_overhead;

#[cfg(not(feature = "async_futures"))]
pub mod async_measurement_overhead {
use criterion::{criterion_group, Criterion};
use criterion2::{criterion_group, Criterion};
fn some_benchmark(_c: &mut Criterion) {}

criterion_group!(benches, some_benchmark);
Expand Down
Loading

0 comments on commit 081785e

Please sign in to comment.