Created
October 16, 2022 17:44
-
-
Save thomasjungblut/8e92d3e9b40f1f9bc67e3c91c3fd5c62 to your computer and use it in GitHub Desktop.
uuid filtering benchmark
This file contains hidden or 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
const _ = require('underscore'); | |
const { Client } = require('pg'); | |
const all_query = `SELECT id FROM "filter-test"."filter-test";`; | |
const some_query = `SELECT id, blob FROM "filter-test"."filter-test" WHERE id IN ('$(WHERE_IN_FILTER)');`; | |
async function query(q) { | |
const client = new Client({ | |
user: 'postgres', | |
database: 'postgres' | |
}); | |
client.connect(); | |
try { | |
return await client.query(q); | |
} finally { | |
client.end(); | |
} | |
} | |
async function main() { | |
console.time("query_all"); | |
let result = await query(all_query); | |
console.timeEnd("query_all"); | |
console.log(result.rows.length); | |
let rows = result.rows.map((e) => e["id"]) | |
benchSize = [1, 10, 100, 1000, 10000, 20000, 50000, 80000]; | |
benchSize.forEach(async n => { | |
let sample = _.sample(rows, n); | |
let q = some_query.replace("$(WHERE_IN_FILTER)", sample.join(`','`)); | |
console.time("query_some_" + n); | |
let rx = await query(q); | |
console.timeEnd("query_some_" + n); | |
console.log(rx.rows.length + " results with query size: " + q.length); | |
}); | |
} | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment