Improve JavaScript benchmarks

This commit is contained in:
Pekka Enberg
2025-01-05 20:43:55 +02:00
parent daee7f8458
commit ec9031dcf8
2 changed files with 49 additions and 7 deletions

View File

@@ -2,13 +2,34 @@ import { run, bench, group, baseline } from 'mitata';
import Database from 'better-sqlite3';
const db = new Database('limbo.db');
const db = new Database('better-sqlite3.db');
const stmt = db.prepare("SELECT 1");
db.exec('CREATE TABLE t (x)');
db.exec('INSERT INTO t VALUES (1)');
db.exec('INSERT INTO t VALUES (2)');
db.exec('INSERT INTO t VALUES (3)');
group('Statement', () => {
group('SQL queries [all()]', () => {
const stmt1 = db.prepare("SELECT 1");
bench('SELECT 1', () => {
stmt.all();
stmt1.all();
});
const stmt2 = db.prepare("SELECT * FROM t");
bench('SELECT * FROM t', () => {
stmt2.all();
});
});
group('SQL queries [iterate()]', () => {
const stmt1 = db.prepare("SELECT 1");
const it1 = stmt1.iterate();
bench('SELECT 1', () => {
it1.next();
});
const stmt2 = db.prepare("SELECT * FROM t");
const it2 = stmt2.iterate();
bench('SELECT * FROM t', () => {
it2.next();
});
});

View File

@@ -4,11 +4,32 @@ import { Database } from 'limbo-wasm';
const db = new Database('limbo.db');
const stmt = db.prepare("SELECT 1");
db.exec('CREATE TABLE t (x)');
db.exec('INSERT INTO t VALUES (1)');
db.exec('INSERT INTO t VALUES (2)');
db.exec('INSERT INTO t VALUES (3)');
group('Statement', () => {
group('SQL queries [all()]', () => {
const stmt1 = db.prepare("SELECT 1");
bench('SELECT 1', () => {
stmt.all();
stmt1.all();
});
const stmt2 = db.prepare("SELECT * FROM t");
bench('SELECT * FROM t', () => {
stmt2.all();
});
});
group('SQL queries [iterate()]', () => {
const stmt1 = db.prepare("SELECT 1");
const it1 = stmt1.iterate();
bench('SELECT 1', () => {
it1.next();
});
const stmt2 = db.prepare("SELECT * FROM t");
const it2 = stmt2.iterate();
bench('SELECT * FROM t', () => {
it2.next();
});
});