|
| 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 | +statement: [ |
| 9 | +'INSERT INTO text_column_type (text_column) VALUES (?)', |
| 10 | +'INSERT INTO integer_column_type (integer_column) VALUES (?)', |
| 11 | +'INSERT INTO real_column_type (real_column) VALUES (?)', |
| 12 | +'INSERT INTO blob_column_type (blob_column) VALUES (?)', |
| 13 | +'INSERT INTO all_column_types (text_column, integer_column, real_column, blob_column) VALUES (?, ?, ?, ?)', |
| 14 | +'INSERT INTO large_text (text_8kb_column) VALUES (?)', |
| 15 | +'INSERT INTO missing_required_value (any_value, required_value) VALUES (?, ?)', |
| 16 | +], |
| 17 | +}); |
| 18 | + |
| 19 | +functionmain(conf){ |
| 20 | +constdb=newsqlite.DatabaseSync(':memory:'); |
| 21 | + |
| 22 | +db.exec('CREATE TABLE text_column_type (text_column TEXT)'); |
| 23 | +db.exec('CREATE TABLE integer_column_type (integer_column INTEGER)'); |
| 24 | +db.exec('CREATE TABLE real_column_type (real_column REAL)'); |
| 25 | +db.exec('CREATE TABLE blob_column_type (blob_column BLOB)'); |
| 26 | +db.exec( |
| 27 | +'CREATE TABLE all_column_types (text_column TEXT, integer_column INTEGER, real_column REAL, blob_column BLOB)', |
| 28 | +); |
| 29 | +db.exec('CREATE TABLE large_text (text_8kb_column TEXT)'); |
| 30 | +db.exec('CREATE TABLE missing_required_value (any_value TEXT, required_value TEXT NOT NULL)'); |
| 31 | + |
| 32 | +constinsertStatement=db.prepare(conf.statement); |
| 33 | + |
| 34 | +leti; |
| 35 | +letdeadCodeElimination; |
| 36 | + |
| 37 | +conststringValue=crypto.randomUUID(); |
| 38 | +constintegerValue=Math.floor(Math.random()*100); |
| 39 | +constrealValue=Math.random(); |
| 40 | +constblobValue=Buffer.from('example blob data'); |
| 41 | + |
| 42 | +constlargeText='a'.repeat(8*1024); |
| 43 | + |
| 44 | +if(conf.statement.includes('text_column_type')){ |
| 45 | +bench.start(); |
| 46 | +for(i=0;i<conf.n;i+=1){ |
| 47 | +deadCodeElimination=insertStatement.run(stringValue); |
| 48 | +} |
| 49 | +bench.end(conf.n); |
| 50 | +}elseif(conf.statement.includes('integer_column_type')){ |
| 51 | +bench.start(); |
| 52 | +for(i=0;i<conf.n;i+=1){ |
| 53 | +deadCodeElimination=insertStatement.run(integerValue); |
| 54 | +} |
| 55 | +bench.end(conf.n); |
| 56 | +}elseif(conf.statement.includes('real_column_type')){ |
| 57 | +bench.start(); |
| 58 | +for(i=0;i<conf.n;i+=1){ |
| 59 | +deadCodeElimination=insertStatement.run(realValue); |
| 60 | +} |
| 61 | +bench.end(conf.n); |
| 62 | +}elseif(conf.statement.includes('blob_column_type')){ |
| 63 | +bench.start(); |
| 64 | +for(i=0;i<conf.n;i+=1){ |
| 65 | +deadCodeElimination=insertStatement.run(blobValue); |
| 66 | +} |
| 67 | +bench.end(conf.n); |
| 68 | +}elseif(conf.statement.includes('INTO all_column_types')){ |
| 69 | +bench.start(); |
| 70 | +for(i=0;i<conf.n;i+=1){ |
| 71 | +deadCodeElimination=insertStatement.run( |
| 72 | +stringValue, |
| 73 | +integerValue, |
| 74 | +realValue, |
| 75 | +blobValue, |
| 76 | +); |
| 77 | +} |
| 78 | +bench.end(conf.n); |
| 79 | +}elseif(conf.statement.includes('INTO large_text')){ |
| 80 | +bench.start(); |
| 81 | +for(i=0;i<conf.n;i+=1){ |
| 82 | +deadCodeElimination=insertStatement.run(largeText); |
| 83 | +} |
| 84 | +bench.end(conf.n); |
| 85 | +}elseif(conf.statement.includes('missing_required_value')){ |
| 86 | +bench.start(); |
| 87 | +for(i=0;i<conf.n;i+=1){ |
| 88 | +try{ |
| 89 | +deadCodeElimination=insertStatement.run(stringValue); |
| 90 | +}catch(e){ |
| 91 | +deadCodeElimination=e; |
| 92 | +} |
| 93 | +} |
| 94 | +bench.end(conf.n); |
| 95 | +}else{ |
| 96 | +thrownewError('Unknown statement'); |
| 97 | +} |
| 98 | + |
| 99 | +assert.ok(deadCodeElimination!==undefined); |
| 100 | +} |
0 commit comments