Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

14 changes: 7 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
"jest": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"import"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"plugins": [
"import"
],
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"rules": {
"linebreak-style": ["error", "unix"],
"no-empty": 1,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ npm install
# build the dist
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import url from 'node:url';
import path from 'node:path';
import b from 'benny';
import { summaryName, suiteCommon } from '../../utils';
import { suiteCommon } from './utils/utils.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const buf = Buffer.allocUnsafe(64);
const summary = await b.suite(
summaryName(__filename),
path.basename(filename, path.extname(filename)),
b.add('JSON stringify and parse buffer', () => {
const bufJSON = JSON.stringify(buf);
Buffer.from(JSON.parse(bufJSON));
Expand All @@ -22,8 +26,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;
15 changes: 11 additions & 4 deletions benches/suites/git/gitgc.ts → benches/git_garbage_collection.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import url from 'node:url';
import path from 'node:path';
import b from 'benny';
import { summaryName, suiteCommon } from '../../utils';
import { suiteCommon } from './utils/utils.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
let map = new Map();
let obj = {};
let arr: any = [];
let set = new Set();
const summary = await b.suite(
summaryName(__filename),
path.basename(filename, path.extname(filename)),
b.add('map', async () => {
map = new Map();
return async () => {
Expand Down Expand Up @@ -83,8 +87,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;
90 changes: 55 additions & 35 deletions benches/index.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,76 @@
#!/usr/bin/env ts-node

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 basicBufferEncodingDecoding from './basic_buffer_encoding_decoding.js';
import gitGarbageCollection from './git_garbage_collection.js';
import keysAsymmetricCrypto from './keys_asymmetric_crypto.js';
import keysKeyGeneration from './keys_key_generation.js';
import keysKeyringLifecycle from './keys_keyring_lifecycle.js';
import keysPasswordHashing from './keys_password_hashing.js';
import keysRandomBytes from './keys_random_bytes.js';
import keysRecoveryCode from './keys_recovery_code.js';
import keysSymmetricCrypto from './keys_symmetric_crypto.js';
import keysX509 from './keys_x509.js';
import workersKeys from './workers_keys.js';
import workersOverhead from './workers_overhead.js';

async function main(): Promise<void> {
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<Summary> = (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 basicBufferEncodingDecoding();
await gitGarbageCollection();
await keysAsymmetricCrypto();
await keysKeyGeneration();
await keysKeyringLifecycle();
await keysPasswordHashing();
await keysRandomBytes();
await keysRecoveryCode();
await keysSymmetricCrypto();
await keysX509();
await workersKeys();
await workersOverhead();
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;
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import url from 'node:url';
import path from 'node:path';
import b from 'benny';
import * as random from '@/keys/utils/random';
import * as generate from '@/keys/utils/generate';
import * as asymmetric from '@/keys/utils/asymmetric';
import { summaryName, suiteCommon } from '../../utils';
import { suiteCommon } from './utils/utils.js';
import * as random from '#keys/utils/random.js';
import * as generate from '#keys/utils/generate.js';
import * as asymmetric from '#keys/utils/asymmetric.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const keyPair = generate.generateKeyPair();
Expand Down Expand Up @@ -34,7 +38,7 @@ async function main() {
plain10KiB,
);
const summary = await b.suite(
summaryName(__filename),
path.basename(filename, path.extname(filename)),
b.add('encrypt 512 B of data', () => {
asymmetric.encryptWithPublicKey(keyPair.publicKey, plain512B);
}),
Expand Down Expand Up @@ -88,8 +92,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;
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import url from 'node:url';
import path from 'node:path';
import b from 'benny';
import * as generate from '@/keys/utils/generate';
import * as recoveryCode from '@/keys/utils/recoveryCode';
import { summaryName, suiteCommon } from '../../utils';
import { suiteCommon } from './utils/utils.js';
import * as generate from '#keys/utils/generate.js';
import * as recoveryCode from '#keys/utils/recoveryCode.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const code = recoveryCode.generateRecoveryCode(24);
const summary = await b.suite(
summaryName(__filename),
path.basename(filename, path.extname(filename)),
b.add('generate root asymmetric keypair', () => {
generate.generateKeyPair();
}),
Expand All @@ -21,8 +25,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;
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import fs from 'fs';
import os from 'os';
import path from 'path';
import fs from 'node:fs';
import os from 'node:os';
import url from 'node:url';
import path from 'node:path';
import b from 'benny';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import KeyRing from '@/keys/KeyRing';
import { summaryName, suiteCommon } from '../../utils';
import { suiteCommon } from './utils/utils.js';
import KeyRing from '#keys/KeyRing.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const summary = await b.suite(
summaryName(__filename),
path.basename(filename, path.extname(filename)),
b.add('KeyRing fresh creation', async () => {
const dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'polykey-bench-'),
Expand Down Expand Up @@ -52,8 +55,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;
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import url from 'node:url';
import path from 'node:path';
import b from 'benny';
import * as password from '@/keys/utils/password';
import { summaryName, suiteCommon } from '../../utils';
import { suiteCommon } from './utils/utils.js';
import * as password from '#keys/utils/password.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const summary = await b.suite(
summaryName(__filename),
path.basename(filename, path.extname(filename)),
b.add('password hashing - min', () => {
password.hashPassword(
'password',
Expand Down Expand Up @@ -42,8 +46,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;
33 changes: 33 additions & 0 deletions benches/keys_random_bytes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import path from 'node:path';
import url from 'node:url';
import b from 'benny';
import { suiteCommon } from './utils/utils.js';
import * as random from '#keys/utils/random.js';

const filename = url.fileURLToPath(new URL(import.meta.url));

async function main() {
const summary = await b.suite(
path.basename(filename, path.extname(filename)),
b.add('random 512 B of data', () => {
random.getRandomBytes(512);
}),
b.add('random 1 KiB of data', () => {
random.getRandomBytes(1024);
}),
b.add('random 10 KiB of data', () => {
random.getRandomBytes(1024 * 10);
}),
...suiteCommon,
);
return summary;
}

if (import.meta.url.startsWith('file:')) {
const modulePath = url.fileURLToPath(import.meta.url);
if (process.argv[1] === modulePath) {
void main();
}
}

export default main;
Loading