Add basic benchmarking code
This commit intentionally leaves Cargo.lock untouched so that rebasing is easier in the future.
- Id
- 1b578d92b65495bf91c6c57e32e2f73d8ebfd79d
- Author
- Caio
- Commit time
- 2019-12-11T11:16:36+01:00
Modified .gitignore
tags
/target
.vscode
+crates/cantine/target
Modified crates/cantine/Cargo.toml
zerocopy = "0.2"
[dev-dependencies]
+criterion = "0.2"
+once_cell = "1.2"
+tempfile = "3.1"
# v4 feature added to generate test uuids
uuid = { version = "0.8", features = ["serde", "v4"] }
-tempfile = "3.1"
-once_cell = "1.2"
+
+[[bench]]
+name = "index"
+harness = false
Created crates/cantine/benches/index.rs
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+
+use once_cell::sync::Lazy;
+use std::{env, path::Path};
+use tantivy::{query::AllQuery, Index, Result};
+
+use cantine::{
+ index::Cantine,
+ model::{SearchCursor, Sort},
+};
+
+struct GlobalData {
+ index: Index,
+ cantine: Cantine,
+}
+
+static GLOBAL: Lazy<GlobalData> = Lazy::new(|| {
+ let (index, cantine) =
+ Cantine::open(Path::new(env::var("CANTINE_PATH").unwrap().as_str())).unwrap();
+
+ GlobalData { index, cantine }
+});
+
+fn search_all(num_items: usize) -> Result<()> {
+ let reader = GLOBAL.index.reader()?;
+ let searcher = reader.searcher();
+
+ GLOBAL
+ .cantine
+ .search(
+ &searcher,
+ &AllQuery,
+ num_items,
+ Sort::Relevance,
+ SearchCursor::START,
+ )
+ .unwrap();
+
+ Ok(())
+}
+
+fn basic_all_query_search(c: &mut Criterion) {
+ let reader = GLOBAL.index.reader().unwrap();
+ let searcher = reader.searcher();
+
+ let index_size = searcher.num_docs();
+
+ c.bench_function(
+ format!("search_allquery_{}_{}", index_size, 20).as_str(),
+ |b| b.iter(|| search_all(black_box(20))),
+ );
+}
+
+criterion_group!(benches, basic_all_query_search);
+criterion_main!(benches);