pub struct Bencher<'a> { /* private fields */ }Expand description
Timing harness passed to a #[pg_bench] benchmark function.
Bench functions register exactly one timing loop with either Bencher::iter or
Bencher::iter_batched.
ⓘ
use pgrx_bench::{Bencher, black_box};
#[pg_bench]
fn bench_normalize_phrase(b: &mut Bencher) {
let phrase = "the quick brown fox";
b.iter(|| crate::normalize_phrase(black_box(phrase)));
}Implementations§
Source§impl<'a> Bencher<'a>
impl<'a> Bencher<'a>
Sourcepub fn iter<R, F>(&mut self, routine: F)where
F: FnMut() -> R + 'a,
pub fn iter<R, F>(&mut self, routine: F)where
F: FnMut() -> R + 'a,
Registers a simple timing loop for a benchmark.
Use this when the benchmark body can reuse the same captured inputs for each iteration.
ⓘ
use pgrx_bench::{Bencher, black_box};
#[pg_bench]
fn bench_parse_uuid(b: &mut Bencher) {
let input = "550e8400-e29b-41d4-a716-446655440000";
b.iter(|| crate::parse_uuid(black_box(input)));
}Sourcepub fn iter_batched<I, R, S, F>(
&mut self,
setup: S,
routine: F,
batch_size: BatchSize,
)
pub fn iter_batched<I, R, S, F>( &mut self, setup: S, routine: F, batch_size: BatchSize, )
Registers a timing loop that performs per-batch setup outside the measured routine body.
Use this when each timing sample needs fresh inputs or temporary state.
ⓘ
use pgrx_bench::{BatchSize, Bencher};
#[pg_bench]
fn bench_transform_rows(b: &mut Bencher) {
b.iter_batched(
|| (0..100).collect::<Vec<i32>>(),
|rows| rows.into_iter().map(|value| value * 2).collect::<Vec<_>>(),
BatchSize::SmallInput,
);
}Auto Trait Implementations§
impl<'a> Freeze for Bencher<'a>
impl<'a> !RefUnwindSafe for Bencher<'a>
impl<'a> !Send for Bencher<'a>
impl<'a> !Sync for Bencher<'a>
impl<'a> Unpin for Bencher<'a>
impl<'a> UnsafeUnpin for Bencher<'a>
impl<'a> !UnwindSafe for Bencher<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more