Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repot_bench to test with on-memory files. #225

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 57 additions & 27 deletions core/benches/report_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,46 @@ use std::path::Path;

use bumpalo::Bump;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use log::LevelFilter;
use okane_core::{
load::{self, LoadError},
report, syntax,
load::LoadError,
report::{self, query::PostingQuery},
syntax,
};
use pretty_assertions::assert_eq;
use testing::{new_example, ExampleInput, FakeFileSink, FileSink, RealFileSink};

pub mod testing;

fn load_benchmark(c: &mut Criterion) {
let input = testing::ExampleInput::new(Path::new("report_bench")).unwrap();
c.bench_function("load-with-counter", |b| {
let input = new_example::<FakeFileSink>(Path::new("report_bench")).unwrap();

basic_asserts(&input);

c.bench_function("load-on-memory", |b| {
b.iter(|| {
let mut count = 0;
load::new_loader(input.rootpath().to_owned())
input
.new_loader()
.load(|_, _, _: &syntax::tracked::LedgerEntry| {
count += 1;
Ok::<(), LoadError>(())
})
.unwrap();
black_box(());
black_box(count)
})
});

let input = new_example::<RealFileSink>(Path::new("report_bench")).unwrap();

basic_asserts(&input);

c.bench_function("load-on-file", |b| {
b.iter(|| {
let mut count = 0;
input
.new_loader()
.load(|_, _, _: &syntax::tracked::LedgerEntry| {
count += 1;
Ok::<(), LoadError>(())
Expand All @@ -27,34 +54,27 @@ fn load_benchmark(c: &mut Criterion) {
}

fn report_process_benchmark(c: &mut Criterion) {
let input = new_example::<FakeFileSink>(Path::new("report_bench")).unwrap();
let opts = report::ProcessOptions::default();
let input = testing::ExampleInput::new(Path::new("report_bench")).unwrap();

c.bench_function("process", |b| {
b.iter(|| {
let arena = Bump::new();
let mut ctx = report::ReportContext::new(&arena);
let ret = report::process(
&mut ctx,
load::new_loader(input.rootpath().to_owned()),
&opts,
)
.expect("report::process must succeed");
let ret = report::process(&mut ctx, input.new_loader(), &opts)
.expect("report::process must succeed");
black_box(ret);
})
});
}

fn query_postings(c: &mut Criterion) {
let input = testing::ExampleInput::new(Path::new("report_bench")).unwrap();
let input = new_example::<FakeFileSink>(Path::new("report_bench")).unwrap();
let arena = Bump::new();
let mut ctx = report::ReportContext::new(&arena);
let opts = report::ProcessOptions::default();
let ledger = report::process(
&mut ctx,
load::new_loader(input.rootpath().to_owned()),
&opts,
)
.expect("report::process must succeed");
let ledger =
report::process(&mut ctx, input.new_loader(), &opts).expect("report::process must succeed");

c.bench_function("query-posting-one-account", |b| {
b.iter(|| {
Expand All @@ -66,16 +86,12 @@ fn query_postings(c: &mut Criterion) {
});
}
fn query_balance(c: &mut Criterion) {
let input = testing::ExampleInput::new(Path::new("report_bench")).unwrap();
let input = new_example::<FakeFileSink>(Path::new("report_bench")).unwrap();
let arena = Bump::new();
let mut ctx = report::ReportContext::new(&arena);
let opts = report::ProcessOptions::default();
let ledger = report::process(
&mut ctx,
load::new_loader(input.rootpath().to_owned()),
&opts,
)
.expect("report::process must succeed");
let ledger =
report::process(&mut ctx, input.new_loader(), &opts).expect("report::process must succeed");

c.bench_function("query-balance-default", |b| {
b.iter(|| {
Expand All @@ -84,9 +100,23 @@ fn query_balance(c: &mut Criterion) {
});
}

fn basic_asserts<T: FileSink>(input: &ExampleInput<T>) {
let arena = Bump::new();
let mut ctx = report::ReportContext::new(&arena);
let opts = report::ProcessOptions::default();
let ledger =
report::process(&mut ctx, input.new_loader(), &opts).expect("report::process must succeed");
let num_txns = ledger.transactions().count();

assert_eq!(testing::num_transactions(), num_txns as u64);
}

#[ctor::ctor]
fn init() {
let _ = env_logger::builder().is_test(true).try_init();
let _ = env_logger::builder()
.is_test(true)
.filter_level(LevelFilter::max())
.try_init();
}

criterion_group!(
Expand Down
Loading