| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,61 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common.js'); | ||
| 3 | + const sqlite = require('node:sqlite'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const bench = common.createBenchmark(main, { | ||
| 7 | + n: [1e5], | ||
| 8 | + tableSeedSize: [1e5], | ||
| 9 | + statement: [ | ||
| 10 | + 'SELECT 1', | ||
| 11 | + 'SELECT * FROM foo LIMIT 1', | ||
| 12 | + 'SELECT * FROM foo LIMIT 100', | ||
| 13 | + 'SELECT text_column FROM foo LIMIT 1', | ||
| 14 | + 'SELECT text_column FROM foo LIMIT 100', | ||
| 15 | + 'SELECT text_column, integer_column FROM foo LIMIT 1', | ||
| 16 | + 'SELECT text_column, integer_column FROM foo LIMIT 100', | ||
| 17 | + 'SELECT text_column, integer_column, real_column FROM foo LIMIT 1', | ||
| 18 | + 'SELECT text_column, integer_column, real_column FROM foo LIMIT 100', | ||
| 19 | + 'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1', | ||
| 20 | + 'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 100', | ||
| 21 | + 'SELECT text_8kb_column FROM foo_large LIMIT 1', | ||
| 22 | + 'SELECT text_8kb_column FROM foo_large LIMIT 100', | ||
| 23 | + ], | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + function main(conf) { | ||
| 27 | + const db = new sqlite.DatabaseSync(':memory:'); | ||
| 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'), | ||
| 40 | + ); | ||
| 41 | + } | ||
| 42 | + | ||
| 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 | + } | ||
| 49 | + | ||
| 50 | + let i; | ||
| 51 | + let deadCodeElimination; | ||
| 52 | + | ||
| 53 | + const stmt = db.prepare(conf.statement); | ||
| 54 | + | ||
| 55 | + bench.start(); | ||
| 56 | + for (i = 0; i < conf.n; i += 1) | ||
| 57 | + deadCodeElimination = stmt.all(); | ||
| 58 | + bench.end(conf.n); | ||
| 59 | + | ||
| 60 | + assert.ok(deadCodeElimination !== undefined); | ||
| 61 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments