@@ -11,32 +11,61 @@ const selectBenchmarks = require('./select');
1111async function runBenchmarks ( ) {
1212 console . log ( 'Running sqlite3 benchmarks...\n' ) ;
1313
14- const suite = new Bench ( {
15- time : 500 , // Run each benchmark for 500ms
16- warmupTime : 50 , // Warmup time in ms
17- warmupIterations : 5 , // Minimum warmup iterations
18- } ) ;
14+ const results = [ ] ;
1915
20- // Add insert benchmarks
16+ // Run insert benchmarks
2117 console . log ( '=== INSERT BENCHMARKS ===\n' ) ;
2218 for ( const [ name , benchmark ] of Object . entries ( insertBenchmarks . benchmarks ) ) {
19+ console . log ( `Running: insert: ${ name } ` ) ;
20+ const suite = new Bench ( {
21+ iterations : 100 ,
22+ warmupIterations : 5 ,
23+ } ) ;
24+
2325 suite . add ( `insert: ${ name } ` , benchmark . fn , {
2426 beforeEach : benchmark . beforeEach ,
2527 afterEach : benchmark . afterEach ,
2628 } ) ;
29+
30+ await suite . run ( ) ;
31+ const task = suite . tasks [ 0 ] ;
32+ if ( task . result && task . result . latency ) {
33+ results . push ( {
34+ name : `insert: ${ name } ` ,
35+ throughput : task . result . throughput ?. mean ,
36+ latency : task . result . latency . mean ,
37+ rme : task . result . latency . rme ,
38+ samples : task . result . latency . samplesCount ,
39+ } ) ;
40+ }
2741 }
2842
29- // Add select benchmarks
30- console . log ( '=== SELECT BENCHMARKS ===\n' ) ;
43+ // Run select benchmarks (fewer iterations since they're slower)
44+ console . log ( '\n === SELECT BENCHMARKS ===\n' ) ;
3145 for ( const [ name , benchmark ] of Object . entries ( selectBenchmarks . benchmarks ) ) {
46+ console . log ( `Running: select: ${ name } ` ) ;
47+ const suite = new Bench ( {
48+ iterations : 10 ,
49+ warmupIterations : 1 ,
50+ } ) ;
51+
3252 suite . add ( `select: ${ name } ` , benchmark . fn , {
3353 beforeAll : benchmark . beforeAll ,
3454 afterAll : benchmark . afterAll ,
3555 } ) ;
36- }
3756
38- // Run all benchmarks
39- await suite . run ( ) ;
57+ await suite . run ( ) ;
58+ const task = suite . tasks [ 0 ] ;
59+ if ( task . result && task . result . latency ) {
60+ results . push ( {
61+ name : `select: ${ name } ` ,
62+ throughput : task . result . throughput ?. mean ,
63+ latency : task . result . latency . mean ,
64+ rme : task . result . latency . rme ,
65+ samples : task . result . latency . samplesCount ,
66+ } ) ;
67+ }
68+ }
4069
4170 // Output results with full precision
4271 console . log ( '\n=== RESULTS ===\n' ) ;
@@ -53,31 +82,25 @@ async function runBenchmarks() {
5382 console . log ( '-' . repeat ( 102 ) ) ;
5483
5584 // Results
56- for ( const task of suite . tasks ) {
57- if ( task . result && task . result . samples && task . result . samples . length > 0 ) {
58- // tinybench v6: result has hz (ops/sec), mean (ms), rme (relative margin of error)
59- const opsSec = task . result . hz . toFixed ( 2 ) ;
60- const avgTime = ( task . result . mean * 1e6 ) . toFixed ( 2 ) ; // Convert ms to nanoseconds
61- const margin = task . result . rme . toFixed ( 2 ) ;
62- const samples = task . result . samples . length ;
85+ for ( const result of results ) {
86+ const opsSec = result . throughput ?. toFixed ( 2 ) || 'N/A' ;
87+ const avgTime = ( result . latency * 1e6 ) . toFixed ( 2 ) ; // Convert ms to nanoseconds
88+ const margin = result . rme ?. toFixed ( 2 ) || 'N/A' ;
89+ const samples = result . samples || 0 ;
6390
64- const row = [
65- task . name . padEnd ( 45 ) ,
66- opsSec . padStart ( 15 ) ,
67- avgTime . padStart ( 20 ) ,
68- ( margin + '%' ) . padStart ( 12 ) ,
69- samples . toString ( ) . padStart ( 10 )
70- ] . join ( '' ) ;
71- console . log ( row ) ;
72- } else if ( task . result ?. error ) {
73- console . log ( `${ task . name . padEnd ( 45 ) } ERROR: ${ task . result . error . message } ` ) ;
74- } else {
75- console . log ( `${ task . name . padEnd ( 45 ) } No results` ) ;
76- }
91+ const row = [
92+ result . name . padEnd ( 45 ) ,
93+ opsSec . padStart ( 15 ) ,
94+ avgTime . padStart ( 20 ) ,
95+ ( margin + '%' ) . padStart ( 12 ) ,
96+ samples . toString ( ) . padStart ( 10 )
97+ ] . join ( '' ) ;
98+ console . log ( row ) ;
7799 }
78100}
79101
80- runBenchmarks ( ) . catch ( ( err ) => {
81- console . error ( 'Benchmark failed:' , err ) ;
82- process . exit ( 1 ) ;
83- } ) ;
102+ runBenchmarks ( )
103+ . catch ( ( err ) => {
104+ console . error ( 'Benchmark failed:' , err ) ;
105+ process . exit ( 1 ) ;
106+ } ) ;
0 commit comments