From 7232683dfe0c96d409f622c27f2be8d63bbfd83b Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 8 May 2024 11:13:29 -0300 Subject: [PATCH] core: Fix benchmark --- core/benches/benchmark.rs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/core/benches/benchmark.rs b/core/benches/benchmark.rs index 98b822a91..aa05406b1 100644 --- a/core/benches/benchmark.rs +++ b/core/benches/benchmark.rs @@ -1,10 +1,11 @@ use criterion::{criterion_group, criterion_main, Criterion, Throughput}; -use limbo_core::{Database, IO}; +use limbo_core::{Database, PlatformIO}; use pprof::criterion::{Output, PProfProfiler}; +use std::rc::Rc; fn bench_db() -> Database { - let io = IO::default(); - Database::open(io, "../testing/hello.db").unwrap() + let io = Rc::new(PlatformIO::new().unwrap()); + Database::open_file(io, "../testing/hello.db").unwrap() } fn bench(c: &mut Criterion) { @@ -14,24 +15,42 @@ fn bench(c: &mut Criterion) { let db = bench_db(); let conn = db.connect(); - let stmt = conn.prepare("SELECT 1").unwrap(); + let mut stmt = conn.prepare("SELECT 1").unwrap(); group.bench_function("Execute prepared statement: 'SELECT 1'", |b| { b.iter(|| { let mut rows = stmt.query().unwrap(); - let row = rows.next().unwrap().unwrap(); - assert_eq!(row.get::(0).unwrap(), 1); + match rows.next().unwrap() { + limbo_core::RowResult::Row(row) => { + assert_eq!(row.get::(0).unwrap(), 1); + } + limbo_core::RowResult::IO => { + unreachable!(); + } + limbo_core::RowResult::Done => { + unreachable!(); + } + } stmt.reset(); }); }); - let stmt = conn.prepare("SELECT * FROM users LIMIT 1").unwrap(); + let mut stmt = conn.prepare("SELECT * FROM users LIMIT 1").unwrap(); group.bench_function( "Execute prepared statement: 'SELECT * FROM users LIMIT 1'", |b| { b.iter(|| { let mut rows = stmt.query().unwrap(); - let row = rows.next().unwrap().unwrap(); - assert_eq!(row.get::(0).unwrap(), 1); + match rows.next().unwrap() { + limbo_core::RowResult::Row(row) => { + assert_eq!(row.get::(0).unwrap(), 1); + } + limbo_core::RowResult::IO => { + unreachable!(); + } + limbo_core::RowResult::Done => { + unreachable!(); + } + } stmt.reset(); }); },