diff --git a/bench/postgres/.gitignore b/bench/postgres/.gitignore new file mode 100644 index 0000000000..9b1ee42e84 --- /dev/null +++ b/bench/postgres/.gitignore @@ -0,0 +1,175 @@ +# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore + +# Logs + +logs +_.log +npm-debug.log_ +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Caches + +.cache + +# Diagnostic reports (https://nodejs.org/api/report.html) + +report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json + +# Runtime data + +pids +_.pid +_.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover + +lib-cov + +# Coverage directory used by tools like istanbul + +coverage +*.lcov + +# nyc test coverage + +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) + +.grunt + +# Bower dependency directory (https://bower.io/) + +bower_components + +# node-waf configuration + +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) + +build/Release + +# Dependency directories + +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) + +web_modules/ + +# TypeScript cache + +*.tsbuildinfo + +# Optional npm cache directory + +.npm + +# Optional eslint cache + +.eslintcache + +# Optional stylelint cache + +.stylelintcache + +# Microbundle cache + +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history + +.node_repl_history + +# Output of 'npm pack' + +*.tgz + +# Yarn Integrity file + +.yarn-integrity + +# dotenv environment variable files + +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) + +.parcel-cache + +# Next.js build output + +.next +out + +# Nuxt.js build / generate output + +.nuxt +dist + +# Gatsby files + +# Comment in the public line in if your project uses Gatsby and not Next.js + +# https://nextjs.org/blog/next-9-1#public-directory-support + +# public + +# vuepress build output + +.vuepress/dist + +# vuepress v2.x temp and cache directory + +.temp + +# Docusaurus cache and generated files + +.docusaurus + +# Serverless directories + +.serverless/ + +# FuseBox cache + +.fusebox/ + +# DynamoDB Local files + +.dynamodb/ + +# TernJS port file + +.tern-port + +# Stores VSCode versions used for testing VSCode extensions + +.vscode-test + +# yarn v2 + +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# IntelliJ based IDEs +.idea + +# Finder (MacOS) folder config +.DS_Store diff --git a/bench/postgres/README.md b/bench/postgres/README.md new file mode 100644 index 0000000000..93f08efd33 --- /dev/null +++ b/bench/postgres/README.md @@ -0,0 +1,27 @@ +# Postgres table load benchmark + +To install dependencies: + +```bash +bun install +``` + +To run in Bun: + +```bash +bun run ./index.mjs +``` + +To run in Node.js: + +```bash +node index.mjs +``` + +To run in Deno: + +```bash +deno run -A index.mjs +``` + +You will need a localhost Postgres server running. diff --git a/bench/postgres/bun.lockb b/bench/postgres/bun.lockb new file mode 100755 index 0000000000..35c8f9d77e Binary files /dev/null and b/bench/postgres/bun.lockb differ diff --git a/bench/postgres/index.mjs b/bench/postgres/index.mjs new file mode 100644 index 0000000000..19618c51a2 --- /dev/null +++ b/bench/postgres/index.mjs @@ -0,0 +1,47 @@ +const isBun = typeof globalThis?.Bun?.sql !== "undefined"; +import postgres from "postgres"; +const sql = isBun ? Bun.sql : postgres; + +// Create the table if it doesn't exist +await sql` + CREATE TABLE IF NOT EXISTS "users_bun_bench" ( + id SERIAL PRIMARY KEY, + first_name TEXT NOT NULL, + last_name TEXT NOT NULL, + email TEXT NOT NULL UNIQUE, + dob TEXT NOT NULL + ) + `; + +// Check if users already exist +const existingUsers = await sql`SELECT COUNT(*) as count FROM "users_bun_bench"`; + +if (+(existingUsers?.[0]?.count ?? existingUsers?.count) < 100) { + // Generate 100 users if none exist + const users = Array.from({ length: 100 }, (_, i) => ({ + first_name: `FirstName${i}`, + last_name: `LastName${i}`, + email: `user${i}@example.com`, + dob: new Date(1970 + Math.floor(Math.random() * 30), Math.floor(Math.random() * 12), Math.floor(Math.random() * 28)) + .toISOString() + .split("T")[0], + })); + + // Insert all users + await sql` + INSERT INTO users_bun_bench (first_name, last_name, email, dob) ${sql(users)} + `; +} + +const type = isBun ? "Bun.sql" : "postgres"; +console.time(type); +let promises = []; +for (let i = 0; i < 100_000; i++) { + promises.push(sql`SELECT * FROM "users_bun_bench" LIMIT 100`); + if (i % 100 === 0 && promises.length > 1) { + await Promise.all(promises); + promises.length = 0; + } +} +await Promise.all(promises); +console.timeEnd(type); diff --git a/bench/postgres/package.json b/bench/postgres/package.json new file mode 100644 index 0000000000..663d54c930 --- /dev/null +++ b/bench/postgres/package.json @@ -0,0 +1,14 @@ +{ + "name": "postgres", + "module": "index.ts", + "type": "module", + "devDependencies": { + "@types/bun": "latest" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "dependencies": { + "postgres": "^3.4.5" + } +} \ No newline at end of file diff --git a/bench/postgres/tsconfig.json b/bench/postgres/tsconfig.json new file mode 100644 index 0000000000..238655f2ce --- /dev/null +++ b/bench/postgres/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM"], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} diff --git a/bench/sqlite/deno.js b/bench/sqlite/deno.js index 74ab5b9ebe..35cc47679e 100644 --- a/bench/sqlite/deno.js +++ b/bench/sqlite/deno.js @@ -1,4 +1,4 @@ -import { Database } from "https://deno.land/x/sqlite3@0.11.1/mod.ts"; +import { Database } from "https://deno.land/x/sqlite3@0.12.0/mod.ts"; import { bench, run } from "../runner.mjs"; const db = new Database("./src/northwind.sqlite"); diff --git a/bench/sqlite/deno.lock b/bench/sqlite/deno.lock new file mode 100644 index 0000000000..d8282381ae --- /dev/null +++ b/bench/sqlite/deno.lock @@ -0,0 +1,82 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denosaurs/plug@1": "1.0.6", + "jsr:@std/assert@0.217": "0.217.0", + "jsr:@std/assert@0.221": "0.221.0", + "jsr:@std/encoding@0.221": "0.221.0", + "jsr:@std/fmt@0.221": "0.221.0", + "jsr:@std/fs@0.221": "0.221.0", + "jsr:@std/path@0.217": "0.217.0", + "jsr:@std/path@0.221": "0.221.0" + }, + "jsr": { + "@denosaurs/plug@1.0.6": { + "integrity": "6cf5b9daba7799837b9ffbe89f3450510f588fafef8115ddab1ff0be9cb7c1a7", + "dependencies": [ + "jsr:@std/encoding", + "jsr:@std/fmt", + "jsr:@std/fs", + "jsr:@std/path@0.221" + ] + }, + "@std/assert@0.217.0": { + "integrity": "c98e279362ca6982d5285c3b89517b757c1e3477ee9f14eb2fdf80a45aaa9642" + }, + "@std/assert@0.221.0": { + "integrity": "a5f1aa6e7909dbea271754fd4ab3f4e687aeff4873b4cef9a320af813adb489a" + }, + "@std/encoding@0.221.0": { + "integrity": "d1dd76ef0dc5d14088411e6dc1dede53bf8308c95d1537df1214c97137208e45" + }, + "@std/fmt@0.221.0": { + "integrity": "379fed69bdd9731110f26b9085aeb740606b20428ce6af31ef6bd45ef8efa62a" + }, + "@std/fs@0.221.0": { + "integrity": "028044450299de8ed5a716ade4e6d524399f035513b85913794f4e81f07da286", + "dependencies": [ + "jsr:@std/assert@0.221", + "jsr:@std/path@0.221" + ] + }, + "@std/path@0.217.0": { + "integrity": "1217cc25534bca9a2f672d7fe7c6f356e4027df400c0e85c0ef3e4343bc67d11", + "dependencies": [ + "jsr:@std/assert@0.217" + ] + }, + "@std/path@0.221.0": { + "integrity": "0a36f6b17314ef653a3a1649740cc8db51b25a133ecfe838f20b79a56ebe0095", + "dependencies": [ + "jsr:@std/assert@0.221" + ] + } + }, + "remote": { + "https://deno.land/x/sqlite3@0.11.1/deno.json": "77126f50d0efce1375173fae94d4df7f732cd25f05d8aa74f8ff801ef4d85caf", + "https://deno.land/x/sqlite3@0.11.1/deps.ts": "d2f23a4489d27ed7ba1f601b86a85ff488a87603e4be7a15f3ea15154fc288ec", + "https://deno.land/x/sqlite3@0.11.1/mod.ts": "3169f246c0eddd6ed82862758f4109f167b7ba5538236240fbb26a129f1bc16c", + "https://deno.land/x/sqlite3@0.11.1/src/blob.ts": "3681353b3c97bc43f9b02f8d1c3269c0dc4eb9cb5d3af16c7ce4d1e1ec7507c4", + "https://deno.land/x/sqlite3@0.11.1/src/constants.ts": "85fd27aa6e199093f25f5f437052e16fd0e0870b96ca9b24a98e04ddc8b7d006", + "https://deno.land/x/sqlite3@0.11.1/src/database.ts": "063281b9b4340c781ba611cb5fef7ab0fc885cb87ed4c8ec123fd772e0da5f8b", + "https://deno.land/x/sqlite3@0.11.1/src/ffi.ts": "6648dc15f10312df9d2fc8e6e2be230d82a552f28b8f77d03f32bbfba9198888", + "https://deno.land/x/sqlite3@0.11.1/src/statement.ts": "5fe86e1a0136a259c055a03988e74490d9d131c058b4c1a18385a6770cd47e2a", + "https://deno.land/x/sqlite3@0.11.1/src/util.ts": "c6604183d2ec5fb17fa0a018572ed5f2317b319dbd7bf48d88a5d06ff25b2cc3", + "https://deno.land/x/sqlite3@0.12.0/deno.json": "b03d6de05f953886662ea987212539af8456a91352684c84af2188520449d42a", + "https://deno.land/x/sqlite3@0.12.0/deps.ts": "d2f23a4489d27ed7ba1f601b86a85ff488a87603e4be7a15f3ea15154fc288ec", + "https://deno.land/x/sqlite3@0.12.0/mod.ts": "3169f246c0eddd6ed82862758f4109f167b7ba5538236240fbb26a129f1bc16c", + "https://deno.land/x/sqlite3@0.12.0/src/blob.ts": "330886fae9714e4a612786f44d8117d65f91e778cf3f40de59b34879fc7ca9ab", + "https://deno.land/x/sqlite3@0.12.0/src/constants.ts": "85fd27aa6e199093f25f5f437052e16fd0e0870b96ca9b24a98e04ddc8b7d006", + "https://deno.land/x/sqlite3@0.12.0/src/database.ts": "4d380d7f0e5a2cf74635a9fcd2b4e27373533f2816cde5357067e51fd22ad8d0", + "https://deno.land/x/sqlite3@0.12.0/src/ffi.ts": "795b598eeae4d12f182e7bcdab524b74b0f01d6deae7f4d8ce63f25c06a46154", + "https://deno.land/x/sqlite3@0.12.0/src/statement.ts": "e8ccde898aef47c7a2514953aca5359a44a285bc3dc0de5819d66f891f477be1", + "https://deno.land/x/sqlite3@0.12.0/src/util.ts": "c6604183d2ec5fb17fa0a018572ed5f2317b319dbd7bf48d88a5d06ff25b2cc3" + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:better-sqlite3@8.5.0" + ] + } + } +}