diff --git a/.eslintrc b/.eslintrc index c9869cd0..05116a25 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,19 +7,18 @@ "jest": true }, "parser": "@typescript-eslint/parser", - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:prettier/recommended", - "prettier" - ], - "plugins": [ - "import" - ], "parserOptions": { "project": "tsconfig.json", "sourceType": "module" }, + "plugins": [ + "import" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" + ], "rules": { "linebreak-style": ["error", "unix"], "no-empty": 1, @@ -182,3 +181,4 @@ ] } } + diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 82fea2eb..b42f3843 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -6,6 +6,10 @@ on: - 'v*.*.*' workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: use-native-library-js-tag: permissions: diff --git a/Cargo.lock b/Cargo.lock index 52957cf4..e29e5e0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -388,7 +388,7 @@ dependencies = [ [[package]] name = "quic" -version = "1.3.13" +version = "2.0.8" dependencies = [ "boring", "napi", diff --git a/Cargo.toml b/Cargo.toml index f736dc1b..8176b749 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "quic" -version = "1.3.13" +version = "2.0.8" authors = ["Roger Qiu "] license-file = "LICENSE" edition = "2021" diff --git a/README.md b/README.md index fef5ac81..3382819c 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ npm run prebuild # build the dist and native objects npm run build # run the repl (this allows you to import from ./src) -npm run ts-node +npm run tsx # run the tests npm run test # lint the source code diff --git a/benches/suites/buffers/buffer_allocation.ts b/benches/buffer_allocation.ts similarity index 71% rename from benches/suites/buffers/buffer_allocation.ts rename to benches/buffer_allocation.ts index 34b3cd69..13d9d7be 100644 --- a/benches/suites/buffers/buffer_allocation.ts +++ b/benches/buffer_allocation.ts @@ -1,9 +1,13 @@ +import path from 'node:path'; +import url from 'node:url'; import b from 'benny'; -import { summaryName, suiteCommon } from '../../utils'; +import { suiteCommon } from './utils/index.js'; + +const filePath = url.fileURLToPath(import.meta.url); async function main() { const summary = await b.suite( - summaryName(__filename), + path.basename(filePath, path.extname(filePath)), b.add('Buffer.alloc', () => { Buffer.alloc(1350); }), @@ -39,8 +43,11 @@ async function main() { return summary; } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/index.ts b/benches/index.ts index 553f154f..7ad06a28 100644 --- a/benches/index.ts +++ b/benches/index.ts @@ -1,56 +1,58 @@ -#!/usr/bin/env ts-node +#!/usr/bin/env tsx -import type { Summary } from 'benny/lib/internal/common-types'; -import fs from 'fs'; -import path from 'path'; +import fs from 'node:fs'; +import path from 'node:path'; +import url from 'node:url'; import si from 'systeminformation'; -import { fsWalk, resultsPath, suitesPath } from './utils'; +import { benchesPath } from './utils/utils.js'; +import buffer_allocation from './buffer_allocation.js'; +import stream_1KiB from './stream_1KiB.js'; +import stream_1KiB_FFI from './stream_1KiB_FFI.js'; async function main(): Promise { - await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true }); - // Running all suites - for await (const suitePath of fsWalk(suitesPath)) { - // Skip over non-ts and non-js files - const ext = path.extname(suitePath); - if (ext !== '.ts' && ext !== '.js') { - continue; - } - const suite: () => Promise = (await import(suitePath)).default; - // Skip default exports that are not functions and are not called "main" - // They might be utility files - if (typeof suite === 'function' && suite.name === 'main') { - await suite(); - } - } - // Concatenating metrics - const metricsPath = path.join(resultsPath, 'metrics.txt'); - await fs.promises.rm(metricsPath, { force: true }); + await fs.promises.mkdir(path.join(benchesPath, 'results'), { + recursive: true, + }); + await buffer_allocation(); + await stream_1KiB(); + await stream_1KiB_FFI(); + const resultFilenames = await fs.promises.readdir( + path.join(benchesPath, 'results'), + ); + const metricsFile = await fs.promises.open( + path.join(benchesPath, 'results', 'metrics.txt'), + 'w', + ); let concatenating = false; - for await (const metricPath of fsWalk(resultsPath)) { - // Skip over non-metrics files - if (!metricPath.endsWith('_metrics.txt')) { - continue; + for (const resultFilename of resultFilenames) { + if (/.+_metrics\.txt$/.test(resultFilename)) { + const metricsData = await fs.promises.readFile( + path.join(benchesPath, 'results', resultFilename), + ); + if (concatenating) { + await metricsFile.write('\n'); + } + await metricsFile.write(metricsData); + concatenating = true; } - const metricData = await fs.promises.readFile(metricPath); - if (concatenating) { - await fs.promises.appendFile(metricsPath, '\n'); - } - await fs.promises.appendFile(metricsPath, metricData); - concatenating = true; } + await metricsFile.close(); const systemData = await si.get({ cpu: '*', osInfo: 'platform, distro, release, kernel, arch', system: 'model, manufacturer', }); await fs.promises.writeFile( - path.join(__dirname, 'results', 'system.json'), + path.join(benchesPath, 'results', 'system.json'), JSON.stringify(systemData, null, 2), ); } -if (require.main === module) { - void main(); +if (import.meta.url.startsWith('file:')) { + const modulePath = url.fileURLToPath(import.meta.url); + if (process.argv[1] === modulePath) { + void main(); + } } export default main; diff --git a/benches/results/buffers/buffer_allocation.chart.html b/benches/results/buffer_allocation.chart.html similarity index 75% rename from benches/results/buffers/buffer_allocation.chart.html rename to benches/results/buffer_allocation.chart.html index fa03e13b..881dfe8c 100644 --- a/benches/results/buffers/buffer_allocation.chart.html +++ b/benches/results/buffer_allocation.chart.html @@ -5,7 +5,7 @@ - buffers.buffer_allocation + buffer_allocation