-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Added a benchmark script for our sql parser (#2708)
- Loading branch information
1 parent
4432c42
commit 9b6de68
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Running Benchmarks | ||
|
||
The easiest way to run all benchmarks is by using the npm script: | ||
|
||
```sh | ||
> npm run bench | ||
``` | ||
|
||
If you need to run a single benchmark suite, for example the sql parser | ||
benchmarks, it is easiest to run and view the output by: | ||
|
||
```sh | ||
> ./bin/run-bench.js lib/db/query-parsers/sql.bench.js && \ | ||
cat benchmark_results/$(ls -1rt benchmark_results | tail -n 1) | ||
``` | ||
|
||
Notice that we do not specify the leading "test/benchmark/" when providing | ||
the benchmark file we want to run. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2024 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict' | ||
|
||
const parseSql = require('../../../../../lib/db/query-parsers/sql') | ||
const benchmark = require('../../../../lib/benchmark') | ||
const suite = benchmark.createBenchmark({ name: 'parseSql', runs: 200_000 }) | ||
|
||
const tests = [ | ||
{ | ||
name: 'leading-multi-line-comment-single-line', | ||
fn: leadingMultiLineCommentSingleLine | ||
}, | ||
{ | ||
name: 'leading-multi-line-comment-multiple-lines', | ||
fn: leadingMultiLineCommentMultipleLines | ||
}, | ||
{ | ||
name: 'single-embedded-multi-line-comment', | ||
fn: singleEmbeddedMultiLineComment | ||
}, | ||
{ | ||
name: 'multiple-embedded-multi-line-comments', | ||
fn: multipleEmbeddedMultiLineComments | ||
}, | ||
{ | ||
name: 'select-statement', | ||
fn: selectStatement | ||
}, | ||
{ | ||
name: 'update-statement', | ||
fn: updateStatement | ||
}, | ||
{ | ||
name: 'delete-statement', | ||
fn: deleteStatement | ||
} | ||
] | ||
|
||
for (const test of tests) { | ||
suite.add(test) | ||
} | ||
suite.run() | ||
|
||
function leadingMultiLineCommentSingleLine() { | ||
parseSql(`/* insert into bar some stuff */ insert into foo (col1)`) | ||
} | ||
|
||
function leadingMultiLineCommentMultipleLines() { | ||
parseSql(`/*insert into bar some stuff*/ | ||
insert into foo (col1) values('bar') | ||
`) | ||
} | ||
|
||
function singleEmbeddedMultiLineComment() { | ||
parseSql(`insert /* insert into bar */ into foo`) | ||
} | ||
|
||
function multipleEmbeddedMultiLineComments() { | ||
parseSql(`insert /* comments! */ into /* insert into bar some stuff */ foo /* MOAR */ (col1)`) | ||
} | ||
|
||
function selectStatement() { | ||
parseSql( | ||
`with foobar (col1) as cte select * from foo as a join on cte using (col1) where a.bar = 'baz'` | ||
) | ||
} | ||
|
||
function updateStatement() { | ||
parseSql(`update foo set bar = 'baz' where col1 = 1`) | ||
} | ||
|
||
function deleteStatement() { | ||
parseSql(`delete from foo where bar = 'baz'`) | ||
} |