@@ -20,25 +20,33 @@ const bench = common.createBenchmark(main, {
2020function main ( conf ) {
2121 const db = new sqlite . DatabaseSync ( ':memory:' ) ;
2222
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 . statment . 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 (?, ?, ?, ?)' ,
3440 ) ;
35- }
3641
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+ }
4250 }
4351
4452 let i ;
@@ -47,8 +55,7 @@ function main(conf) {
4755 const stmt = db . prepare ( conf . statement ) ;
4856
4957 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 ( ) ;
5259 bench . end ( conf . n ) ;
5360
5461 assert . ok ( deadCodeElimination !== undefined ) ;
0 commit comments