Skip to content

Commit

Permalink
SNOW-979081: Run perf test N runs dropping min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Jul 29, 2024
1 parent 28f74d6 commit d7c53d4
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions test/integration/generic/generic_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@ const assert = require('assert');
const generic = require('../../../lib/generic');
const snowflake = require('../../../lib/snowflake');
const testUtil = require('../testUtil');
const { performance } = require('perf_hooks');

const repeatTimesPerfRun = 5;
const runDroppingMinAndMax = async fn => {
const results = [];
for (let i = 0; i < repeatTimesPerfRun; i++) {
const start = performance.now();
await fn();
const end = performance.now();
results.push(end - start);
}
results.sort((a, b) => a - b);
let avg = 0;
for (let i = 1; i < repeatTimesPerfRun - 1; i++) {
avg += results[i];
}
console.log(`Average time is ${avg / (repeatTimesPerfRun - 2)}ms`);

Check failure on line 21 in test/integration/generic/generic_test.js

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected console statement
};

describe.only('test generic binding', () => {
const connectionParams = {
Expand Down Expand Up @@ -101,8 +117,8 @@ describe.only('test generic binding', () => {
});

[10, 10000, 1000000].forEach(sourceRowCount => {
it(`GENERIC|${sourceRowCount}|${resultFormat}|ROWS|${repeatTimesPerfRun}`, () => {
for (let i = 0; i < repeatTimesPerfRun; i++) {
it(`GENERIC|${sourceRowCount}|${resultFormat}|ROWS|${repeatTimesPerfRun}`, async () => {
await runDroppingMinAndMax(() => {
const result = generic.executeQuery(connectionId,
`select randstr(10, random())
from table (generator(rowcount =>${sourceRowCount}))`);
Expand All @@ -112,11 +128,11 @@ describe.only('test generic binding', () => {
assert.equal(row.length, 1);
assert.ok(row[0]);
});
}
});
});

it(`GENERIC|${sourceRowCount}|${resultFormat}|DELAYED|${repeatTimesPerfRun}`, () => {
for (let i = 0; i < repeatTimesPerfRun; i++) {
it(`GENERIC|${sourceRowCount}|${resultFormat}|DELAYED|${repeatTimesPerfRun}`, async () => {
await runDroppingMinAndMax(() => {
const streamRowsSize = 1000;
const statementId = generic.executeQueryWithoutFetchingRows(connectionId,
`select randstr(10, random())
Expand All @@ -137,11 +153,11 @@ describe.only('test generic binding', () => {
}
}
assert.equal(fetchedRows, sourceRowCount);
}
});
});

it(`GENERIC|${sourceRowCount}|${resultFormat}|STREAM|${repeatTimesPerfRun}`, () => {
for (let i = 0; i < repeatTimesPerfRun; i++) {
it(`GENERIC|${sourceRowCount}|${resultFormat}|STREAM|${repeatTimesPerfRun}`, async () => {
await runDroppingMinAndMax(() => {
let fetchedRows = 0;
let invalidRows = 0;
const options = {
Expand All @@ -160,7 +176,7 @@ describe.only('test generic binding', () => {
assert.equal(result.length, 0);
assert.equal(invalidRows, 0);
assert.equal(fetchedRows, sourceRowCount);
}
});
});
});
});
Expand Down Expand Up @@ -192,7 +208,7 @@ describe.only('Perf selects standard nodejs', () => {
const resultFormat = 'JSON';

it(`NODEJS|${sourceRowCount}|${resultFormat}|ROWS|${repeatTimesPerfRun}`, async () => {
for (let i = 0; i < repeatTimesPerfRun; i++) {
await runDroppingMinAndMax(async () => {
const result = await testUtil.executeCmdAsync(connection,
`select randstr(10, random()) as a
from table (generator(rowcount =>${sourceRowCount}))`,
Expand All @@ -202,7 +218,7 @@ describe.only('Perf selects standard nodejs', () => {
assert.ok(row);
assert.ok(row['A']);
});
}
});
});

const countRows = (connection, sqlText, validateRow) => {
Expand Down Expand Up @@ -230,13 +246,13 @@ describe.only('Perf selects standard nodejs', () => {
};

it(`NODEJS|${sourceRowCount}|${resultFormat}|STREAM|${repeatTimesPerfRun}`, async () => {
for (let i = 0; i < repeatTimesPerfRun; i++) {
await runDroppingMinAndMax(async () => {
const rowLength = await countRows(connection,
`select randstr(10, random()) as a
from table (generator(rowcount =>${sourceRowCount}))`,
row => row && row['A']);
assert.equal(rowLength, sourceRowCount);
}
});
});
});
});

0 comments on commit d7c53d4

Please sign in to comment.