sqlitegraph 2.2.2

Embedded graph database with full ACID transactions, HNSW vector search, dual backend support, and comprehensive graph algorithms library
Documentation
//! Focused performance benchmark for V3 after page allocation fix
//!
//! Run with: cargo test --features native-v3 test_v3_focused_perf --release -- --nocapture --test-threads=1

use sqlitegraph::{
    backend::native::v3::V3Backend,
    backend::{GraphBackend, NodeSpec},
};
use std::time::Instant;
use tempfile::TempDir;

#[test]
fn test_v3_focused_perf() {
    println!("\n=== V3 Focused Performance Benchmark ===\n");

    // A. INSERT_NODES BENCHMARK
    println!("A. INSERT_NODES (10K nodes)");
    let temp = TempDir::new().unwrap();
    let db_path = temp.path().join("bench_insert.graph");

    let start = Instant::now();
    {
        let backend = V3Backend::create(&db_path).unwrap();
        for i in 0..10000 {
            backend
                .insert_node(NodeSpec {
                    kind: "Test".to_string(),
                    name: format!("node_{}", i),
                    file_path: None,
                    data: serde_json::json!({"i": i}),
                })
                .unwrap();
            if i > 0 && i % 2000 == 0 {
                println!("  Inserted {} nodes...", i);
            }
        }
        backend.flush_to_disk().unwrap();
    }
    let insert_duration = start.elapsed();
    println!("  INSERT_NODES: {:?}", insert_duration);
    println!(
        "  Throughput: {:.2} nodes/sec",
        10000.0 / insert_duration.as_secs_f64()
    );

    // B. REOPEN_COST BENCHMARK
    println!("\nB. REOPEN_COST");
    let start = Instant::now();
    let _backend = V3Backend::open(&db_path).unwrap();
    let reopen_duration = start.elapsed();
    println!("  REOPEN_COST: {:?}", reopen_duration);

    // C. GET_NODE BENCHMARK (simple check)
    println!("\nC. GET_NODE (100 lookups)");
    let backend = V3Backend::open(&db_path).unwrap();
    let start = Instant::now();
    for _i in 0..100 {
        // Just verify get operation works - actual benchmark would need proper IDs
        use sqlitegraph::SnapshotId;
        let _ = backend.get_node(SnapshotId::current(), 5000);
    }
    let get_duration = start.elapsed();
    println!("  GET_NODE (100 lookups): {:?}", get_duration);
    println!("  Avg per lookup: {:?}", get_duration / 100);

    println!("\n=== Benchmark Complete ===");
}