From 0f956fa17990d308da8db42b090935f7c4c9b3f0 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Fri, 14 Apr 2023 11:59:36 +0300 Subject: [PATCH] Use Criterion's throughput estimation Iteration time is of course interesting, but let's also use throughput estimation on MVCC operations such as read(), begin_tx(), etc.. --- core/mvcc/database/benches/my_benchmark.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/core/mvcc/database/benches/my_benchmark.rs b/core/mvcc/database/benches/my_benchmark.rs index 6aead08e5..9425f81e4 100644 --- a/core/mvcc/database/benches/my_benchmark.rs +++ b/core/mvcc/database/benches/my_benchmark.rs @@ -1,12 +1,15 @@ -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, Criterion, Throughput}; use mvcc_rs::clock::LocalClock; use mvcc_rs::database::{Database, Row}; use pprof::criterion::{Output, PProfProfiler}; fn bench(c: &mut Criterion) { + let mut group = c.benchmark_group("mvcc-ops-throughput"); + group.throughput(Throughput::Elements(1)); + let clock = LocalClock::default(); let db = Database::new(clock); - c.bench_function("begin_tx", |b| { + group.bench_function("begin_tx", |b| { b.iter(|| { db.begin_tx(); }) @@ -14,7 +17,7 @@ fn bench(c: &mut Criterion) { let clock = LocalClock::default(); let db = Database::new(clock); - c.bench_function("begin_tx + rollback_tx", |b| { + group.bench_function("begin_tx + rollback_tx", |b| { b.iter(|| { let tx_id = db.begin_tx(); db.rollback_tx(tx_id) @@ -23,7 +26,7 @@ fn bench(c: &mut Criterion) { let clock = LocalClock::default(); let db = Database::new(clock); - c.bench_function("begin_tx + commit_tx", |b| { + group.bench_function("begin_tx + commit_tx", |b| { b.iter(|| { let tx_id = db.begin_tx(); db.commit_tx(tx_id) @@ -41,7 +44,7 @@ fn bench(c: &mut Criterion) { }, ) .unwrap(); - c.bench_function("read", |b| { + group.bench_function("read", |b| { b.iter(|| { db.read(tx, 1).unwrap(); })