SQL BenchMEASURED, NOT GUESSED

    ↑↓ to select, Enter to open, Esc to close

    executemany (one transaction) is ~1.25× faster than execute() per row

    Batching the calls on the Python side is ~25% faster even with a single commit in both cases — a one-line change.

    Result

    Runexecutemany (one transaction)execute() per rowRatio
    Run 115.73719.6550.80×
    Run 214.31017.4950.82×
    Run 314.12218.1500.78×

    Spread over 3 runs: executemany (one transaction) CV 5.0% / execute() per row CV 5.0% / Ratio CV 2.0%

    executemany (one transaction): 15.74msexecute() per row: 19.66msRun1executemany (one transaction): 14.31msexecute() per row: 17.50msRun2executemany (one transaction): 14.12msexecute() per row: 18.15msRun3

    The statement

    con.executemany('INSERT INTO items VALUES (?,?,?,?,?)', rows); con.commit()
    for r in rows: con.execute('INSERT INTO items VALUES (?,?,?,?,?)', r)
    con.commit()

    Conditions

    5,000 rows inserted into an 8,000-row table, no indexes, `synchronous=NORMAL`.

    Where this number does not apply

    With very large rows, or when you must commit mid-way, the gap narrows.

    Reproduce

    cd bench && python sqbench.py --samples 9 --out ../data/run.json