Skip to content

not very fast for large sql #28

@veryrandomname

Description

@veryrandomname

IN List Parse Benchmark - v0.1.7

fyi, the current tokenizer/parser are slow b/c they copy strings again and again.
this is by no way an expecation for you to fix this. just calling it out here.

Size: 1000000 items
Warmup: 1 iteration(s)
Iterations: 10
SQL size: 9888917 bytes
Summary:
Mean: 647.414 ms
Min: 627.917 ms
Max: 660.274 ms
Benchmark code:

use std::hint::black_box;
use std::time::Instant;
fn main() {
    let size = 1_000_000;
    let warmup = 1;
    let iterations = 10;
    println!("IN List Parse Benchmark - v0.1.7");
    println!("=================================");
    println!("Size: {} items", size);
    println!("Warmup: {} iteration(s)", warmup);
    println!("Iterations: {}", iterations);
    println!();
    let values: Vec<String> = (0..size).map(|i| format!("'{i}'")).collect();
    let sql = format!("SELECT * FROM t WHERE x IN ({})", values.join(", "));
    println!("SQL size: {} bytes", sql.len());
    println!();
    let dialect = polyglot_sql::dialects::Dialect::get(polyglot_sql::dialects::DialectType::Generic);
    for _ in 0..warmup {
        let _ = dialect.parse(&sql);
    }
    let mut times = Vec::with_capacity(iterations);
    for i in 0..iterations {
        let start = Instant::now();
        let result = black_box(dialect.parse(black_box(&sql)));
        let elapsed = start.elapsed();
        times.push(elapsed.as_secs_f64() * 1000.0);
        
        if let Ok(stmts) = result {
            println!("Run {:2}: {:.3} ms ({} statements)", 
                i + 1, elapsed.as_secs_f64() * 1000.0, stmts.len());
        }
    }
    println!();
    let mean: f64 = times.iter().sum::<f64>() / times.len() as f64;
    let min = times.iter().cloned().fold(f64::INFINITY, f64::min);
    let max = times.iter().cloned().fold(f64::NEG_INFINITY, f64::max);
    
    println!("Summary:");
    println!("  Mean: {:.3} ms", mean);
    println!("  Min:  {:.3} ms", min);
    println!("  Max:  {:.3} ms", max);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions