()
| 5 | |
| 6 | #[tokio::test] |
| 7 | async fn test_insert_performance_comparison() { |
| 8 | println!("\n=== INSERT PERFORMANCE COMPARISON ===\n"); |
| 9 | |
| 10 | let iterations = 1000; |
| 11 | |
| 12 | // Test 1: Direct SQLite (baseline) |
| 13 | println!("1. Direct SQLite (baseline):"); |
| 14 | let conn = Connection::open_in_memory().expect("Failed to create SQLite connection"); |
| 15 | conn.execute("CREATE TABLE baseline_test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER)", []) |
| 16 | .expect("Failed to create table"); |
| 17 | |
| 18 | let start = Instant::now(); |
| 19 | for i in 0..iterations { |
| 20 | conn.execute( |
| 21 | "INSERT INTO baseline_test (name, value) VALUES (?1, ?2)", |
| 22 | rusqlite::params![format!("test{}", i), i] |
| 23 | ).expect("Failed to execute INSERT"); |
| 24 | } |
| 25 | let sqlite_time = start.elapsed(); |
| 26 | let sqlite_avg = sqlite_time / iterations as u32; |
| 27 | println!(" Total: {sqlite_time:?}, Average: {sqlite_avg:?}"); |
| 28 | |
| 29 | // Test 2: pgsqlite with non-decimal table (fast path) |
| 30 | println!("\n2. pgsqlite - Non-decimal table (fast path):"); |
| 31 | let db = DbHandler::new(":memory:").expect("Failed to create database"); |
| 32 | |
| 33 | // Create a session |
| 34 | let session_id = Uuid::new_v4(); |
| 35 | db.create_session_connection(session_id).await.expect("Failed to create session connection"); |
| 36 | |
| 37 | db.execute_with_session("CREATE TABLE fast_test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER)", &session_id) |
| 38 | .await |
| 39 | .expect("Failed to create table"); |
| 40 | |
| 41 | let start = Instant::now(); |
| 42 | for i in 0..iterations { |
| 43 | let query = format!("INSERT INTO fast_test (name, value) VALUES ('test{i}', {i})"); |
| 44 | db.execute_with_session(&query, &session_id).await.expect("Failed to execute INSERT"); |
| 45 | } |
| 46 | let fast_time = start.elapsed(); |
| 47 | let fast_avg = fast_time / iterations as u32; |
| 48 | println!(" Total: {fast_time:?}, Average: {fast_avg:?}"); |
| 49 | println!(" Overhead vs SQLite: {:.1}x", fast_avg.as_secs_f64() / sqlite_avg.as_secs_f64()); |
| 50 | |
| 51 | // Test 3: pgsqlite with decimal table (slow path) |
| 52 | println!("\n3. pgsqlite - Decimal table (slow path):"); |
| 53 | db.execute_with_session("CREATE TABLE decimal_test (id INTEGER PRIMARY KEY, price DECIMAL(10,2), name TEXT)", &session_id) |
| 54 | .await |
| 55 | .expect("Failed to create table"); |
| 56 | |
| 57 | let start = Instant::now(); |
| 58 | for i in 0..iterations { |
| 59 | let query = format!("INSERT INTO decimal_test (price, name) VALUES ({i}.99, 'test{i}')"); |
| 60 | db.execute_with_session(&query, &session_id).await.expect("Failed to execute INSERT"); |
| 61 | } |
| 62 | let decimal_time = start.elapsed(); |
| 63 | let decimal_avg = decimal_time / iterations as u32; |
| 64 | println!(" Total: {decimal_time:?}, Average: {decimal_avg:?}"); |
nothing calls this directly
no test coverage detected