diff --git a/geoffrey_api/src/commands/selling.rs b/geoffrey_api/src/commands/selling.rs index c09ed82..ec260c9 100644 --- a/geoffrey_api/src/commands/selling.rs +++ b/geoffrey_api/src/commands/selling.rs @@ -71,3 +71,82 @@ impl Command for Selling { Ok(shops) } } + +#[cfg(test)] +mod test { + use crate::commands::selling::Selling; + use crate::commands::Command; + use crate::config::GeoffreyAPIConfig; + use crate::context::Context; + use geoffrey_models::models::item::ItemListing; + use geoffrey_models::models::locations::shop::Shop; + use geoffrey_models::models::locations::{LocationDataDb, LocationDb}; + use geoffrey_models::models::parameters::selling_params::SellingParams; + use geoffrey_models::models::Position; + use std::path::PathBuf; + use std::time::Instant; + + fn test_selling_lookup_speed(iter: i32, shop_count: i32, items_for_sale: i32) -> f32 { + let config = GeoffreyAPIConfig { + db_path: PathBuf::from("test_db/"), + host: "".to_string(), + }; + + let ctx = Context::new(config.clone()).unwrap(); + + let mut shop_data = Shop::default(); + + for _ in 0..items_for_sale { + shop_data + .item_listings + .insert(ItemListing::new("sed", 5, 5)); + } + + for i in 0..shop_count { + let shop = LocationDb::new( + format!("Test Shop {} {}", iter, i).as_str(), + Position::default(), + 0, + None, + LocationDataDb::Shop(shop_data.clone()), + ); + ctx.db.insert(shop).unwrap(); + } + + let start = Instant::now(); + + Selling::run_command( + ctx, + SellingParams { + token: "".to_string(), + query: "sed".to_string(), + sort: None, + order: None, + }, + None, + ) + .unwrap(); + + let query_dur = start.elapsed().as_secs_f32(); + + return query_dur; + } + + #[test] + fn stress_test() { + std::fs::remove_dir_all(PathBuf::from("test_db")).ok(); + println!("Shop Count,Item Count,Query Time,Query Time / Shop"); + for shop_count in (100..=1000).step_by(100) { + let query_dur = test_selling_lookup_speed(shop_count, 100, 10); + + println!( + "{},{},{},{}", + shop_count, + 10, + query_dur, + query_dur / (shop_count as f32) + ); + } + std::fs::remove_dir_all(PathBuf::from("test_db")).ok(); + } +}