| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,25 +26,33 @@ const bench = common.createBenchmark(main, { | |||
| 26 | 26 | function main(conf) { | |
| 27 | 27 | const db = new sqlite.DatabaseSync(':memory:'); | |
| 28 | 28 | ||
| 29 | - 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 (?, ?, ?, ?)', | ||
| 40 | 46 | ); | |
| 41 | - } | ||
| 42 | 47 | ||
| 43 | - 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 | + } | ||
| 48 | 56 | } | |
| 49 | 57 | ||
| 50 | 58 | let i; | |
@@ -53,8 +61,7 @@ function main(conf) { | |||
| 53 | 61 | const stmt = db.prepare(conf.statement); | |
| 54 | 62 | ||
| 55 | 63 | 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(); | ||
| 58 | 65 | bench.end(conf.n); | |
| 59 | 66 | ||
| 60 | 67 | assert.ok(deadCodeElimination !== undefined); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,25 +20,33 @@ const bench = common.createBenchmark(main, { | |||
| 20 | 20 | function main(conf) { | |
| 21 | 21 | const db = new sqlite.DatabaseSync(':memory:'); | |
| 22 | 22 | ||
| 23 | - db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)'); | ||
| 24 | - const fooInsertStatement = db.prepare( | ||
| 25 | - 'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)', | ||
| 26 | - ); | ||
| 27 | - | ||
| 28 | - for (let i = 0; i < conf.tableSeedSize; i++) { | ||
| 29 | - fooInsertStatement.run( | ||
| 30 | - crypto.randomUUID(), | ||
| 31 | - Math.floor(Math.random() * 100), | ||
| 32 | - Math.random(), | ||
| 33 | - Buffer.from('example blob data'), | ||
| 23 | + // Create only the necessary table for the benchmark type. | ||
| 24 | + // If the statement includes 'foo_large', create the foo_large table; otherwise, create the foo table. | ||
| 25 | + if (conf.statement.includes('foo_large')) { | ||
| 26 | + db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)'); | ||
| 27 | + const fooLargeInsertStatement = db.prepare( | ||
| 28 | + 'INSERT INTO foo_large (text_8kb_column) VALUES (?)', | ||
| 29 | + ); | ||
| 30 | + const largeText = 'a'.repeat(8 * 1024); | ||
| 31 | + for (let i = 0; i < conf.tableSeedSize; i++) { | ||
| 32 | + fooLargeInsertStatement.run(largeText); | ||
| 33 | + } | ||
| 34 | + } else { | ||
| 35 | + db.exec( | ||
| 36 | + 'CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)', | ||
| 37 | + ); | ||
| 38 | + const fooInsertStatement = db.prepare( | ||
| 39 | + 'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)', | ||
| 34 | 40 | ); | |
| 35 | - } | ||
| 36 | 41 | ||
| 37 | - db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)'); | ||
| 38 | - const fooLargeInsertStatement = db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)'); | ||
| 39 | - const largeText = 'a'.repeat(8 * 1024); | ||
| 40 | - for (let i = 0; i < conf.tableSeedSize; i++) { | ||
| 41 | - fooLargeInsertStatement.run(largeText); | ||
| 42 | + for (let i = 0; i < conf.tableSeedSize; i++) { | ||
| 43 | + fooInsertStatement.run( | ||
| 44 | + crypto.randomUUID(), | ||
| 45 | + Math.floor(Math.random() * 100), | ||
| 46 | + Math.random(), | ||
| 47 | + Buffer.from('example blob data'), | ||
| 48 | + ); | ||
| 49 | + } | ||
| 42 | 50 | } | |
| 43 | 51 | ||
| 44 | 52 | let i; | |
@@ -47,8 +55,7 @@ function main(conf) { | |||
| 47 | 55 | const stmt = db.prepare(conf.statement); | |
| 48 | 56 | ||
| 49 | 57 | bench.start(); | |
| 50 | - for (i = 0; i < conf.n; i += 1) | ||
| 51 | - deadCodeElimination = stmt.get(); | ||
| 58 | + for (i = 0; i < conf.n; i += 1) deadCodeElimination = stmt.get(); | ||
| 52 | 59 | bench.end(conf.n); | |
| 53 | 60 | ||
| 54 | 61 | assert.ok(deadCodeElimination !== undefined); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments