()
| 4 | |
| 5 | #[tokio::test] |
| 6 | async fn test_insert_detailed_timing() { |
| 7 | println!("\n=== DETAILED INSERT TIMING ANALYSIS ==="); |
| 8 | |
| 9 | // Use a temporary file instead of in-memory database |
| 10 | let test_id = Uuid::new_v4().to_string().replace("-", ""); |
| 11 | let db_path = format!("/tmp/pgsqlite_test_{test_id}.db"); |
| 12 | |
| 13 | let db = DbHandler::new(&db_path).expect("Failed to create database"); |
| 14 | |
| 15 | // Create a session |
| 16 | let session_id = Uuid::new_v4(); |
| 17 | db.create_session_connection(session_id).await.expect("Failed to create session connection"); |
| 18 | |
| 19 | // Create test table |
| 20 | db.execute_with_session("CREATE TABLE test_insert (id INTEGER PRIMARY KEY, name TEXT, value INTEGER)", &session_id) |
| 21 | .await |
| 22 | .expect("Failed to create table"); |
| 23 | |
| 24 | // Warm up |
| 25 | db.execute_with_session("INSERT INTO test_insert (name, value) VALUES ('warmup', 1)", &session_id) |
| 26 | .await |
| 27 | .expect("Failed to warm up"); |
| 28 | |
| 29 | // Test different INSERT scenarios |
| 30 | let test_cases = vec![ |
| 31 | ("Simple INSERT", "INSERT INTO test_insert (name, value) VALUES ('test1', 100)"), |
| 32 | ("INSERT with single quotes", "INSERT INTO test_insert (name, value) VALUES ('test''s', 200)"), |
| 33 | ("INSERT with numbers", "INSERT INTO test_insert (name, value) VALUES ('test123', 300)"), |
| 34 | ("INSERT with longer values", "INSERT INTO test_insert (name, value) VALUES ('this is a much longer test string that might affect performance', 400)"), |
| 35 | ]; |
| 36 | |
| 37 | println!("\nIndividual INSERT timing:"); |
| 38 | for (desc, query) in &test_cases { |
| 39 | let mut times = Vec::new(); |
| 40 | |
| 41 | // Run each query 10 times to get average |
| 42 | for _ in 0..10 { |
| 43 | let start = Instant::now(); |
| 44 | db.execute_with_session(query, &session_id).await.expect("Failed to execute INSERT"); |
| 45 | times.push(start.elapsed()); |
| 46 | } |
| 47 | |
| 48 | let avg_time = times.iter().sum::<std::time::Duration>() / times.len() as u32; |
| 49 | println!("{desc}: {avg_time:?} (avg of 10 runs)"); |
| 50 | } |
| 51 | |
| 52 | // Test parameterized INSERT through extended protocol |
| 53 | println!("\nParameterized INSERT timing:"); |
| 54 | let param_query = "INSERT INTO test_insert (name, value) VALUES ($1, $2)"; |
| 55 | let mut param_times = Vec::new(); |
| 56 | |
| 57 | for i in 0..10 { |
| 58 | let start = Instant::now(); |
| 59 | db.execute_with_params( |
| 60 | param_query, |
| 61 | &[ |
| 62 | Some(format!("param{i}").into_bytes()), |
| 63 | Some(i.to_string().into_bytes()), |
nothing calls this directly
no test coverage detected