|
| 1 | +'use strict'; |
| 2 | +constcommon=require('../common.js'); |
| 3 | +constsqlite=require('node:sqlite'); |
| 4 | +constassert=require('assert'); |
| 5 | + |
| 6 | +constbench=common.createBenchmark(main,{ |
| 7 | +n: [1e5], |
| 8 | +tableSeedSize: [1e5], |
| 9 | +statement: [ |
| 10 | +'SELECT 1', |
| 11 | +'SELECT * FROM foo LIMIT 1', |
| 12 | +'SELECT text_column FROM foo LIMIT 1', |
| 13 | +'SELECT text_column, integer_column FROM foo LIMIT 1', |
| 14 | +'SELECT text_column, integer_column, real_column FROM foo LIMIT 1', |
| 15 | +'SELECT text_column, integer_column, real_column, blob_column FROM foo LIMIT 1', |
| 16 | +'SELECT text_8kb_column FROM foo_large LIMIT 1', |
| 17 | +], |
| 18 | +}); |
| 19 | + |
| 20 | +functionmain(conf){ |
| 21 | +constdb=newsqlite.DatabaseSync(':memory:'); |
| 22 | + |
| 23 | +db.exec('CREATE TABLE foo (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)'); |
| 24 | +constfooInsertStatement=db.prepare( |
| 25 | +'INSERT INTO foo (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)', |
| 26 | +); |
| 27 | + |
| 28 | +for(leti=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'), |
| 34 | +); |
| 35 | +} |
| 36 | + |
| 37 | +db.exec('CREATE TABLE foo_large (text_8kb_column TEXT)'); |
| 38 | +constfooLargeInsertStatement=db.prepare('INSERT INTO foo_large (text_8kb_column) VALUES (?)'); |
| 39 | +constlargeText='a'.repeat(8*1024); |
| 40 | +for(leti=0;i<conf.tableSeedSize;i++){ |
| 41 | +fooLargeInsertStatement.run(largeText); |
| 42 | +} |
| 43 | + |
| 44 | +leti; |
| 45 | +letdeadCodeElimination; |
| 46 | + |
| 47 | +conststmt=db.prepare(conf.statement); |
| 48 | + |
| 49 | +bench.start(); |
| 50 | +for(i=0;i<conf.n;i+=1) |
| 51 | +deadCodeElimination=stmt.get(); |
| 52 | +bench.end(conf.n); |
| 53 | + |
| 54 | +assert.ok(deadCodeElimination!==undefined); |
| 55 | +} |
0 commit comments