benchmark: sqlite prevent create both tables on prepare selects · nodejs/node@7bbbcf6

@@ -26,25 +26,33 @@ const bench = common.createBenchmark(main, {

2626

function main(conf) {

2727

const db = new sqlite.DatabaseSync(':memory:');

282829-

db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)');

30-

const fooInsertStatement = db.prepare(

31-

'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',

32-

);

33-34-

for (let i = 0; i < conf.tableSeedSize; i++) {

35-

fooInsertStatement.run(

36-

crypto.randomUUID(),

37-

Math.floor(Math.random() * 100),

38-

Math.random(),

39-

Buffer.from('example blob data'),

29+

// Create only the necessary table for the benchmark type.

30+

// If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table.

31+

if (conf.statement.includes('foo_large')) {

32+

db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');

33+

const fooLargeInsertStatement = db.prepare(

34+

'INSERT INTO foo_large (text_8kb_column) VALUES (?)',

35+

);

36+

const largeText = 'a'.repeat(8 * 1024);

37+

for (let i = 0; i < conf.tableSeedSize; i++) {

38+

fooLargeInsertStatement.run(largeText);

39+

}

40+

} else {

41+

db.exec(

42+

'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)',

43+

);

44+

const fooInsertStatement = db.prepare(

45+

'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)',

4046

);

41-

}

424743-

db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)');

44-

const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)');

45-

const largeText = 'a'.repeat(8 * 1024);

46-

for (let i = 0; i < conf.tableSeedSize; i++) {

47-

fooLargeInsertStatement.run(largeText);

48+

for (let i = 0; i < conf.tableSeedSize; i++) {

49+

fooInsertStatement.run(

50+

crypto.randomUUID(),

51+

Math.floor(Math.random() * 100),

52+

Math.random(),

53+

Buffer.from('example blob data'),

54+

);

55+

}

4856

}

49575058

let i;

@@ -53,8 +61,7 @@ function main(conf) {

5361

const stmt = db.prepare(conf.statement);

54625563

bench.start();

56-

for (i = 0; i < conf.n; i += 1)

57-

deadCodeElimination = stmt.all();

64+

for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.all();

5865

bench.end(conf.n);

59666067

assert.ok(deadCodeElimination !== undefined);