Use bencher instead of unstable libtest

This commit is contained in:
Thom Chiovoloni
2020-04-07 08:33:17 -07:00
parent c0df911946
commit 7e4ff77a43
3 changed files with 25 additions and 25 deletions

18
benches/cache.rs Normal file
View File

@@ -0,0 +1,18 @@
use bencher::{benchmark_group, benchmark_main, Bencher};
use rusqlite::Connection;
fn bench_no_cache(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap();
db.set_prepared_statement_cache_capacity(0);
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
b.iter(|| db.prepare(sql).unwrap());
}
fn bench_cache(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap();
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
b.iter(|| db.prepare_cached(sql).unwrap());
}
benchmark_group!(cache_benches, bench_no_cache, bench_cache);
benchmark_main!(cache_benches);

View File

@@ -1,24 +0,0 @@
#![cfg_attr(feature = "unstable", feature(test))]
#[cfg(feature = "unstable")]
mod bench {
extern crate test;
use rusqlite::Connection;
use test::Bencher;
#[bench]
fn bench_no_cache(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap();
db.set_prepared_statement_cache_capacity(0);
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
b.iter(|| db.prepare(sql).unwrap());
}
#[bench]
fn bench_cache(b: &mut Bencher) {
let db = Connection::open_in_memory().unwrap();
let sql = "SELECT 1, 'test', 3.14 UNION SELECT 2, 'exp', 2.71";
b.iter(|| db.prepare_cached(sql).unwrap());
}
}