@@ -29,7 +29,7 @@ async function destroyDatabaseAsync(connection: SQLiteCloudConnection, database:
2929 connection . close ( )
3030}
3131
32- const BRC_TIMEOUT = 15 * 60 * 1000 // 15 minutes
32+ const BRC_TIMEOUT = 12 * 60 * 60 * 1000 // 12 hours
3333jest . setTimeout ( BRC_TIMEOUT ) // Set global timeout
3434
3535describe ( '1 billion row challenge' , ( ) => {
@@ -43,16 +43,26 @@ describe('1 billion row challenge', () => {
4343 it ( 'should create 500_000 measurements' , async ( ) => {
4444 await createMeasurements ( 500_000 )
4545 } )
46- it ( 'should run 500_000 row challenge' , async ( ) => {
46+ it ( 'should run 500_000 row challenge with chunked inserts ' , async ( ) => {
4747 await testChallenge ( 500_000 )
4848 } )
49+ it ( 'should run 500_000 row challenge with a single insert statement' , async ( ) => {
50+ await testChallenge ( 500_000 , 500_000 )
51+ } )
4952
5053 it ( 'should create 10_000_000 measurements' , async ( ) => {
5154 await createMeasurements ( 10_000_000 )
5255 } )
5356 it ( 'should run 10_000_000 row challenge' , async ( ) => {
5457 await testChallenge ( 10_000_000 )
5558 } )
59+
60+ it ( 'should create 100_000_000 measurements' , async ( ) => {
61+ await createMeasurements ( 100_000_000 )
62+ } )
63+ it ( 'should run 100_000_000 row challenge' , async ( ) => {
64+ await testChallenge ( 100_000_000 )
65+ } )
5666} )
5767
5868//
@@ -111,7 +121,7 @@ async function createMeasurements(numberOfRows: number = 1000000) {
111121 console . log ( `Wrote 1brc_${ numberOfRows } _rows.csv in ${ Date . now ( ) - startedOn } ms` )
112122}
113123
114- async function testChallenge ( numberOfRows : number ) {
124+ async function testChallenge ( numberOfRows : number , insertChunks = BRC_INSERT_CHUNKS ) {
115125 const startedOn = Date . now ( )
116126
117127 const { connection, database } = await createDatabaseAsync ( numberOfRows )
@@ -128,14 +138,14 @@ async function testChallenge(numberOfRows: number) {
128138 expect ( lines . length ) . toBe ( numberOfRows )
129139 const uniqueStations = new Set ( data . map ( item => item . city ) )
130140 expect ( uniqueStations . size ) . toBe ( BRC_UNIQUE_STATIONS )
131- console . debug ( `Parsed ${ numberOfRows } rows .csv file in ${ Date . now ( ) - parseOn } ms` )
141+ console . debug ( `Read 1brc_ ${ numberOfRows } _rows .csv in ${ Date . now ( ) - parseOn } ms` )
132142
133143 // create database and table
134144 const createResult = await sendCommandsAsync ( connection , `CREATE TABLE measurements(city VARCHAR(26), temp FLOAT);` )
135145 expect ( createResult ) . toBe ( 'OK' )
136146
137- const insertOn = Date . now ( )
138147 for ( let chunk = 0 , startRow = 0 ; startRow < numberOfRows ; chunk ++ , startRow += BRC_INSERT_CHUNKS ) {
148+ const insertOn = Date . now ( )
139149 // insert chunk of rows into sqlite database
140150 const dataChunk = data . slice ( startRow , Math . min ( numberOfRows , startRow + BRC_INSERT_CHUNKS ) )
141151 const values = dataChunk . map ( ( { city, temp } ) => `('${ city . replaceAll ( "'" , "''" ) } ', ${ temp } )` ) . join ( ',\n' )
@@ -148,8 +158,8 @@ async function testChallenge(numberOfRows: number) {
148158 const insertResult = ( await sendCommandsAsync ( connection , insertSql ) ) as Array < number >
149159 expect ( Array . isArray ( insertResult ) ) . toBeTruthy ( )
150160 expect ( insertResult [ 3 ] as number ) . toBe ( dataChunk . length ) // totalChanges
161+ console . debug ( `Inserted ${ dataChunk . length } rows in ${ Date . now ( ) - insertOn } ms` )
151162 }
152- console . debug ( `Inserted ${ numberOfRows } rows in ${ Date . now ( ) - insertOn } ms` )
153163
154164 // calculate averages, etc
155165 const selectOn = Date . now ( )
@@ -160,6 +170,11 @@ async function testChallenge(numberOfRows: number) {
160170 console . debug ( `Selected ${ numberOfRows } rows with aggregates in ${ Date . now ( ) - selectOn } ms` )
161171
162172 console . log ( `Ran ${ numberOfRows } challenge in ${ Date . now ( ) - startedOn } ms` )
173+
174+ // write results to csv
175+ const selectCsvPathname = path . resolve ( __dirname , 'assets/1brc' , `1brc_${ numberOfRows } _rows_results.csv` )
176+ const selectCsv = selectResult . map ( row => `"${ row . city } ",${ row [ 'MIN(temp)' ] } ,${ ( row [ 'AVG(temp)' ] as number ) . toFixed ( 2 ) } ,${ row [ 'MAX(temp)' ] } ` ) . join ( '\n' )
177+ fs . writeFileSync ( selectCsvPathname , selectCsv )
163178 } catch ( error ) {
164179 console . error ( `An error occoured while running 1brc, error: ${ error } ` )
165180 throw error
0 commit comments