@@ -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 ) ;
0 commit comments