one transaction (500 rows) is ~250.00× faster than commit per row
The biggest gap on this site: 500 rows in one transaction is 250× faster than committing per row. The difference is 500 disk syncs vs one.
Result
| Run | one transaction (500 rows) | commit per row | Ratio |
|---|---|---|---|
| Run 1 | 8.038 | 2221.983 | 0.00× |
| Run 2 | 7.607 | 2057.993 | 0.00× |
| Run 3 | 8.425 | 2039.464 | 0.00× |
Spread over 3 runs: one transaction (500 rows) CV 4.2% / commit per row CV 4.0% / Ratio CV 0.0%
The statement
con.execute('BEGIN')
con.executemany('INSERT INTO items VALUES (?,?,?,?,?)', rows)
con.commit() for r in rows:
con.execute('INSERT INTO items VALUES (?,?,?,?,?)', r)
con.commit() Conditions
500 rows inserted into an 8,000-row table; `journal_mode=DELETE`, `synchronous=NORMAL`.
Where this number does not apply
The magnitude changes on non-SSD storage and with `synchronous=OFF`; fewer rows means a smaller gap.
Reproduce
cd bench && python sqbench.py --samples 9 --out ../data/run.json