Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add node:sqlite benchmark #1334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

weary-adventurer
Copy link

@weary-adventurer weary-adventurer commented Feb 28, 2025

This adds a benchmark for the built-in node:sqlite module available with --experimental-sqlite since Node v22.5.0.
This benchmark will only run and be included in the results if the node:sqlite module exists and is available.

Known issues:

  1. This creates prepared statements for every query instead of reusing persistent statements because DatabaseSync.prepare is a wrapper for sqlite3_prepare_v2 that doesn't accept SQLITE_PREPARE_PERSISTENT flag.
  2. Iterate benchmark does nothing for now as StatementSync.iterate was added in Node v23.4.0 but even after updating it fails with "statement has been finalized".

This is probably OK as a first pass and will be more useful later as the built-in module gets more stable.

Fixes #1266.

$ node --experimental-sqlite benchmark
--- reading rows individually ---
better-sqlite3 x 121,663 ops/sec ±0.29%
node-sqlite3   x 12,805 ops/sec ±0.47%
node:sqlite    x 52,115 ops/sec ±1.66%

--- reading 100 rows into an array ---
better-sqlite3 x 6,750 ops/sec ±0.41%
node-sqlite3   x 1,641 ops/sec ±0.8%
node:sqlite    x 10,170 ops/sec ±0.42%

--- iterating over 100 rows ---
better-sqlite3 x 5,732 ops/sec ±0.44%
node-sqlite3   x 132 ops/sec ±1.78%
node:sqlite    x NaN ops/sec ±NaN% // See [2]

--- inserting rows individually ---
better-sqlite3 x 39,821 ops/sec ±4.34%
node-sqlite3   x 11,392 ops/sec ±1.21%
node:sqlite    x 26,655 ops/sec ±2.28%

--- inserting 100 rows in a single transaction ---
better-sqlite3 x 3,996 ops/sec ±3.2%
node-sqlite3   x 105 ops/sec ±1.38%
node:sqlite    x 2,906 ops/sec ±2.71%

All benchmarks complete!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

node:sqlite and benchmarking
1 participant