()
| 6 | |
| 7 | #[tokio::test] |
| 8 | async fn test_protocol_overhead_breakdown() { |
| 9 | println!("\n=== PROTOCOL OVERHEAD BREAKDOWN ===\n"); |
| 10 | |
| 11 | // Use a temporary file instead of in-memory database |
| 12 | let test_id = Uuid::new_v4().to_string().replace("-", ""); |
| 13 | let db_path = format!("/tmp/pgsqlite_test_{test_id}.db"); |
| 14 | |
| 15 | let db = std::sync::Arc::new(DbHandler::new(&db_path).expect("Failed to create database")); |
| 16 | |
| 17 | // Create a session for testing |
| 18 | let session_id = Uuid::new_v4(); |
| 19 | db.create_session_connection(session_id).await.expect("Failed to create session connection"); |
| 20 | |
| 21 | // Create test table |
| 22 | db.execute_with_session("CREATE TABLE protocol_test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER)", &session_id) |
| 23 | .await |
| 24 | .expect("Failed to create table"); |
| 25 | |
| 26 | let iterations = 1000; |
| 27 | |
| 28 | // Test 1: Direct DbHandler execution (no protocol) |
| 29 | println!("1. Direct DbHandler execution (no protocol):"); |
| 30 | let start = Instant::now(); |
| 31 | for i in 0..iterations { |
| 32 | let query = format!("INSERT INTO protocol_test (name, value) VALUES ('direct{i}', {i})"); |
| 33 | db.execute_with_session(&query, &session_id).await.expect("Failed to execute INSERT"); |
| 34 | } |
| 35 | let direct_time = start.elapsed(); |
| 36 | let direct_avg = direct_time / iterations as u32; |
| 37 | println!(" Total: {direct_time:?}, Average: {direct_avg:?}"); |
| 38 | |
| 39 | // Test 2: Measure components of INSERT execution |
| 40 | println!("\n2. Component timing for single INSERT:"); |
| 41 | |
| 42 | let test_query = "INSERT INTO protocol_test (name, value) VALUES ('component', 999)"; |
| 43 | |
| 44 | // Measure fast path detection |
| 45 | let start = Instant::now(); |
| 46 | for _ in 0..100 { |
| 47 | let _ = pgsqlite::query::fast_path::can_use_fast_path_enhanced(test_query); |
| 48 | } |
| 49 | let fast_path_time = start.elapsed() / 100; |
| 50 | println!(" Fast path detection: {fast_path_time:?}"); |
| 51 | |
| 52 | // Measure schema cache lookup |
| 53 | let start = Instant::now(); |
| 54 | for _ in 0..100 { |
| 55 | let _ = db.get_table_schema("protocol_test").await; |
| 56 | } |
| 57 | let schema_time = start.elapsed() / 100; |
| 58 | println!(" Schema cache lookup: {schema_time:?}"); |
| 59 | |
| 60 | // Test 3: Batch execution to identify per-query vs per-connection overhead |
| 61 | println!("\n3. Batch execution analysis:"); |
| 62 | |
| 63 | // Execute multiple INSERTs in a loop to simulate batch |
| 64 | let start = Instant::now(); |
| 65 | for batch in 0..100 { |
nothing calls this directly
no test coverage detected