tangle


git clone https://radroots.dev/git/tangle.git
Log | Files | Refs | README | LICENSE

commit 08fcf789302c6fd8914481da027ed60200440e3f
parent 5282b5fd4f0e65f0835046aa65d3f6f96e6d37f3
Author: triesap <tyson@radroots.org>
Date:   Sat,  6 Jun 2026 02:56:32 -0700

bench: add search benchmark

Diffstat:
Mcrates/tangle_bench/src/lib.rs | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+), 0 deletions(-)

diff --git a/crates/tangle_bench/src/lib.rs b/crates/tangle_bench/src/lib.rs @@ -302,6 +302,60 @@ pub async fn run_listing_query_benchmark( }) } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct SearchBenchmarkReport { + pub indexed: u64, + pub text_results: u64, + pub browse_results: u64, + pub elapsed_micros: u128, +} + +pub async fn run_search_benchmark( + config: BenchDatasetConfig, +) -> Result<SearchBenchmarkReport, String> { + let dataset = BenchDataset::generate(config)?; + let materialized = materialize_listing_workload(&dataset).await?; + let store = materialized.store(); + let mut indexed = 0; + for event in dataset.listings() { + if store + .index_listing_search_document(event) + .await + .map_err(|error| error.to_string())? + == SearchDocumentOutcome::Indexed + { + indexed += 1; + } + } + let started = Instant::now(); + let text_results = store + .query_search_documents( + &SearchDocumentQuery::new() + .with_text("carrots") + .with_doc_type("listing") + .with_visible(true), + ) + .await + .map_err(|error| error.to_string())? + .len() as u64; + let browse_results = store + .query_search_documents( + &SearchDocumentQuery::new() + .with_doc_type("listing") + .with_visible(true) + .with_limit(9), + ) + .await + .map_err(|error| error.to_string())? + .len() as u64; + Ok(SearchBenchmarkReport { + indexed, + text_results, + browse_results, + elapsed_micros: started.elapsed().as_micros(), + }) +} + async fn bench_memory_store(database: &str) -> Result<SurrealStore, String> { let config = SurrealConnectionConfig::memory("tangle_bench", database) .map_err(|error| error.to_string())?; @@ -510,4 +564,16 @@ mod tests { assert_eq!(report.limited_rows, 7); assert!(report.elapsed_micros > 0); } + + #[tokio::test] + async fn search_benchmark_reports_deterministic_query_counts() { + let report = super::run_search_benchmark(BenchDatasetConfig::new(16, 0)) + .await + .expect("search benchmark"); + + assert_eq!(report.indexed, 16); + assert_eq!(report.text_results, 16); + assert_eq!(report.browse_results, 9); + assert!(report.elapsed_micros > 0); + } }