|
| 1 | +/* |
| 2 | + * Copyright 2024 New Relic Corporation. All rights reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +'use strict' |
| 7 | + |
| 8 | +const parseSql = require('../../../../../lib/db/query-parsers/sql') |
| 9 | +const benchmark = require('../../../../lib/benchmark') |
| 10 | +const suite = benchmark.createBenchmark({ name: 'parseSql', runs: 200_000 }) |
| 11 | + |
| 12 | +const tests = [ |
| 13 | + { |
| 14 | + name: 'leading-multi-line-comment-single-line', |
| 15 | + fn: leadingMultiLineCommentSingleLine |
| 16 | + }, |
| 17 | + { |
| 18 | + name: 'leading-multi-line-comment-multiple-lines', |
| 19 | + fn: leadingMultiLineCommentMultipleLines |
| 20 | + }, |
| 21 | + { |
| 22 | + name: 'single-embedded-multi-line-comment', |
| 23 | + fn: singleEmbeddedMultiLineComment |
| 24 | + }, |
| 25 | + { |
| 26 | + name: 'multiple-embedded-multi-line-comments', |
| 27 | + fn: multipleEmbeddedMultiLineComments |
| 28 | + }, |
| 29 | + { |
| 30 | + name: 'select-statement', |
| 31 | + fn: selectStatement |
| 32 | + }, |
| 33 | + { |
| 34 | + name: 'update-statement', |
| 35 | + fn: updateStatement |
| 36 | + }, |
| 37 | + { |
| 38 | + name: 'delete-statement', |
| 39 | + fn: deleteStatement |
| 40 | + } |
| 41 | +] |
| 42 | + |
| 43 | +for (const test of tests) { |
| 44 | + suite.add(test) |
| 45 | +} |
| 46 | +suite.run() |
| 47 | + |
| 48 | +function leadingMultiLineCommentSingleLine() { |
| 49 | + parseSql(`/* insert into bar some stuff */ insert into foo (col1)`) |
| 50 | +} |
| 51 | + |
| 52 | +function leadingMultiLineCommentMultipleLines() { |
| 53 | + parseSql(`/*insert into bar some stuff*/ |
| 54 | + insert into foo (col1) values('bar') |
| 55 | + `) |
| 56 | +} |
| 57 | + |
| 58 | +function singleEmbeddedMultiLineComment() { |
| 59 | + parseSql(`insert /* insert into bar */ into foo`) |
| 60 | +} |
| 61 | + |
| 62 | +function multipleEmbeddedMultiLineComments() { |
| 63 | + parseSql(`insert /* comments! */ into /* insert into bar some stuff */ foo /* MOAR */ (col1)`) |
| 64 | +} |
| 65 | + |
| 66 | +function selectStatement() { |
| 67 | + parseSql( |
| 68 | + `with foobar (col1) as cte select * from foo as a join on cte using (col1) where a.bar = 'baz'` |
| 69 | + ) |
| 70 | +} |
| 71 | + |
| 72 | +function updateStatement() { |
| 73 | + parseSql(`update foo set bar = 'baz' where col1 = 1`) |
| 74 | +} |
| 75 | + |
| 76 | +function deleteStatement() { |
| 77 | + parseSql(`delete from foo where bar = 'baz'`) |
| 78 | +} |
0 commit comments