test: add benchmark for flinksql (#120)

This commit is contained in:
Ziv 2023-06-13 09:28:48 +08:00 committed by GitHub
parent e34a9f6128
commit e914cf2c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19857 additions and 10 deletions

View File

@ -1,4 +1,4 @@
lockfileVersion: 5.3
lockfileVersion: 5.4
specifiers:
'@swc/core': ^1.3.60
@ -26,8 +26,8 @@ devDependencies:
'@swc/jest': 0.2.26_@swc+core@1.3.60
'@types/jest': 29.5.1
'@types/node': 18.16.16
'@typescript-eslint/eslint-plugin': 3.10.1_a18e814019c959d52a44881c5533ce12
'@typescript-eslint/parser': 3.10.1_eslint@7.32.0+typescript@5.0.4
'@typescript-eslint/eslint-plugin': 3.10.1_ughicqazzfm5kkseraofkm6oci
'@typescript-eslint/parser': 3.10.1_cgdknpc562nnyruteofhkegnom
antlr4ts-cli: 0.5.0-alpha.4
eslint: 7.32.0
eslint-config-google: 0.14.0_eslint@7.32.0
@ -751,6 +751,7 @@ packages:
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
libc: [glibc]
requiresBuild: true
dev: true
optional: true
@ -760,6 +761,7 @@ packages:
engines: {node: '>=10'}
cpu: [arm64]
os: [linux]
libc: [musl]
requiresBuild: true
dev: true
optional: true
@ -769,6 +771,7 @@ packages:
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
libc: [glibc]
requiresBuild: true
dev: true
optional: true
@ -778,6 +781,7 @@ packages:
engines: {node: '>=10'}
cpu: [x64]
os: [linux]
libc: [musl]
requiresBuild: true
dev: true
optional: true
@ -944,7 +948,7 @@ packages:
'@types/yargs-parser': 21.0.0
dev: true
/@typescript-eslint/eslint-plugin/3.10.1_a18e814019c959d52a44881c5533ce12:
/@typescript-eslint/eslint-plugin/3.10.1_ughicqazzfm5kkseraofkm6oci:
resolution: {integrity: sha512-PQg0emRtzZFWq6PxBcdxRH3QIQiyFO3WCVpRL3fgj5oQS3CDs3AeAKfv4DxNhzn8ITdNJGJ4D3Qw8eAJf3lXeQ==}
engines: {node: ^10.12.0 || >=12.0.0}
peerDependencies:
@ -955,8 +959,8 @@ packages:
typescript:
optional: true
dependencies:
'@typescript-eslint/experimental-utils': 3.10.1_eslint@7.32.0+typescript@5.0.4
'@typescript-eslint/parser': 3.10.1_eslint@7.32.0+typescript@5.0.4
'@typescript-eslint/experimental-utils': 3.10.1_cgdknpc562nnyruteofhkegnom
'@typescript-eslint/parser': 3.10.1_cgdknpc562nnyruteofhkegnom
debug: 4.3.4
eslint: 7.32.0
functional-red-black-tree: 1.0.1
@ -968,7 +972,7 @@ packages:
- supports-color
dev: true
/@typescript-eslint/experimental-utils/3.10.1_eslint@7.32.0+typescript@5.0.4:
/@typescript-eslint/experimental-utils/3.10.1_cgdknpc562nnyruteofhkegnom:
resolution: {integrity: sha512-DewqIgscDzmAfd5nOGe4zm6Bl7PKtMG2Ad0KG8CUZAHlXfAKTF9Ol5PXhiMh39yRL2ChRH1cuuUGOcVyyrhQIw==}
engines: {node: ^10.12.0 || >=12.0.0}
peerDependencies:
@ -985,7 +989,7 @@ packages:
- typescript
dev: true
/@typescript-eslint/parser/3.10.1_eslint@7.32.0+typescript@5.0.4:
/@typescript-eslint/parser/3.10.1_cgdknpc562nnyruteofhkegnom:
resolution: {integrity: sha512-Ug1RcWcrJP02hmtaXVS3axPPTTPnZjupqhgj+NnZ6BCkwSImWk/283347+x9wN+lqOdK9Eo3vsyiyDHgsmiEJw==}
engines: {node: ^10.12.0 || >=12.0.0}
peerDependencies:
@ -996,7 +1000,7 @@ packages:
optional: true
dependencies:
'@types/eslint-visitor-keys': 1.0.0
'@typescript-eslint/experimental-utils': 3.10.1_eslint@7.32.0+typescript@5.0.4
'@typescript-eslint/experimental-utils': 3.10.1_cgdknpc562nnyruteofhkegnom
'@typescript-eslint/types': 3.10.1
'@typescript-eslint/typescript-estree': 3.10.1_typescript@5.0.4
eslint: 7.32.0
@ -1543,8 +1547,8 @@ packages:
engines: {node: '>=10'}
hasBin: true
dependencies:
is-text-path: 1.0.1
JSONStream: 1.3.5
is-text-path: 1.0.1
lodash: 4.17.21
meow: 8.1.2
split2: 3.2.2

View File

@ -28,3 +28,41 @@ export const readSQL = (dirname: string, fileName: string) => {
return result;
};
/**
* Benchmark for a function.
* @param name
* @param fn
* @param times , default 1
* @returns [ totalTime, averageTime, msg ]
*/
export function benchmark(name: string, fn: Function, times: number = 1): [number, number, string] {
const start = performance.now();
for (let i = 0; i < times; i++) {
fn();
}
const end = performance.now();
const totalTime = end - start;
const averageTime = totalTime / times;
const msg = `Benchmark: ${name} executed ${times} times. Total time: ${totalTime.toFixed(2)}ms. Average time: ${averageTime.toFixed(2)}ms`;
console.log(msg)
return [totalTime, averageTime, msg];
}
export function getReportTableRow(name, rows, times, totalTime, averageTime) {
return `| ${name} | ${rows} | ${times} | ${totalTime.toFixed(2)} | ${averageTime.toFixed(2)} |`;
}
export function getReportTableHeader(title: string) {
return `# ${title}
| Name | Rows | Times | Total Time(ms) | Average Time(ms) |
| ---- | ---- | ---- | ---- | ---- |\n`;
}
export function exportReportTable(markdown: string, output: string) {
fs.writeFileSync(path.join(output, 'benchmark.md'), markdown);
}

View File

@ -0,0 +1,12 @@
# FlinkSQL Benchmark
| Name | Rows | Times | Total Time(ms) | Average Time(ms) |
| ---- | ---- | ---- | ---- | ---- |
| CreateTable | 100 | 1 | 208.57 | 208.57 |
| CreateTable | 1000 | 1 | 336.50 | 336.50 |
| CreateTable | 5000 | 1 | 1798.17 | 1798.17 |
| SelectTable | 100 | 1 | 327.30 | 327.30 |
| SelectTable | 1000 | 1 | 833.60 | 833.60 |
| SelectTable | 5000 | 1 | 4058.11 | 4058.11 |
| InsertTable | 100 | 1 | 10.45 | 10.45 |
| InsertTable | 1000 | 1 | 45.08 | 45.08 |
| InsertTable | 5000 | 1 | 259.14 | 259.14 |

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
import path from 'path';
import { writeFileSync } from 'node:fs';
import FlinkSQL from '../../../../src/parser/flinksql';
import { readSQL, benchmark, getReportTableHeader, getReportTableRow, exportReportTable } from '../../../helper';
const features = {
selectTable: readSQL(__dirname, 'selectTable.sql'),
createTable: readSQL(__dirname, 'createTable.sql'),
insertTable: readSQL(__dirname, 'insertTable.sql'),
};
describe('FlinkSQL benchmark tests', () => {
const parser = new FlinkSQL();
let reportsHeader = getReportTableHeader('FlinkSQL Benchmark');
const reportData: string[] = [];
test('createTable Over 100 Rows', async () => {
const [totalTimes, averageTimes , msg] = benchmark('CreateTable Over 100 Rows', () => {
const testSQL = features.createTable[0];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('CreateTable', 100, 1, totalTimes, averageTimes));
});
test('createTable Over 1000 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 1000 Rows', () => {
const testSQL = features.createTable[1];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('CreateTable', 1000, 1, totalTimes, averageTimes));
});
test('createTable Over 5000 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('CreateTable Over 5000 Rows', () => {
const testSQL = features.createTable[2];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('CreateTable', 5000, 1, totalTimes, averageTimes));
});
test('selectTable Over 100 Rows', async () => {
const [totalTimes, averageTimes , msg] = benchmark('SelectTable Over 100 Rows', () => {
const testSQL = features.selectTable[0];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('SelectTable', 100, 1, totalTimes, averageTimes));
});
test('selectTable Over 1000 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('SelectTable Over 1000 Rows', () => {
const testSQL = features.selectTable[1];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('SelectTable', 1000, 1, totalTimes, averageTimes));
});
test('selectTable Over 5000 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('SelectTable Over 5000 Rows', () => {
const testSQL = features.selectTable[2];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('SelectTable', 5000, 1, totalTimes, averageTimes));
});
test('insertTable Over 100 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('InsertTable Over 100 Rows', () => {
const testSQL = features.insertTable[0];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('InsertTable', 100, 1, totalTimes, averageTimes));
});
test('insertTable Over 1000 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('InsertTable Over 1000 Rows', () => {
const testSQL = features.insertTable[1];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('InsertTable', 1000, 1, totalTimes, averageTimes));
});
test('insertTable Over 5000 Rows', async () => {
const [totalTimes, averageTimes, msg] = benchmark('InsertTable Over 5000 Rows', () => {
const testSQL = features.insertTable[2];
const res = parser.validate(testSQL);
expect(res).toEqual([])
});
reportData.push(getReportTableRow('InsertTable', 5000, 1, totalTimes, averageTimes));
});
afterAll(() => {
exportReportTable(reportsHeader + reportData.join('\n'), __dirname)
})
});