mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-28 21:44:21 +01:00
core: Fix benchmark
This commit is contained in:
@@ -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::<i64>(0).unwrap(), 1);
|
||||
match rows.next().unwrap() {
|
||||
limbo_core::RowResult::Row(row) => {
|
||||
assert_eq!(row.get::<i64>(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::<i64>(0).unwrap(), 1);
|
||||
match rows.next().unwrap() {
|
||||
limbo_core::RowResult::Row(row) => {
|
||||
assert_eq!(row.get::<i64>(0).unwrap(), 1);
|
||||
}
|
||||
limbo_core::RowResult::IO => {
|
||||
unreachable!();
|
||||
}
|
||||
limbo_core::RowResult::Done => {
|
||||
unreachable!();
|
||||
}
|
||||
}
|
||||
stmt.reset();
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user