Skip to content

Commit 238f569

Browse files
committed
bench: fixing benchmarks
1 parent a776b90 commit 238f569

File tree

8 files changed

+101
-107
lines changed

8 files changed

+101
-107
lines changed

benches/crypto_100KiB.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EFSWorker } from "#efsWorker.js";
1+
import type { EFSWorker } from '#efsWorker.js';
22
import os from 'node:os';
33
import path from 'node:path';
44
import url from 'node:url';
@@ -8,7 +8,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { WorkerManager } from '@matrixai/workers';
99
import { suiteCommon } from './utils/index.js';
1010
import * as utils from '#utils.js';
11-
import efsWorker from "#efsWorker.js";
11+
import efsWorker from '#efsWorker.js';
1212

1313
const logger = new Logger('crypto100KiB Bench', LogLevel.WARN, [
1414
new StreamHandler(),
@@ -19,13 +19,12 @@ const workerPath = path.join(filename, '../../dist/efsWorker');
1919
async function main() {
2020
const cores = os.cpus().length;
2121
logger.warn(`Cores: ${cores}`);
22-
const workerManager =
23-
await WorkerManager.createWorkerManager<EFSWorker>({
24-
workerFactory: () => new Worker(workerPath),
25-
manifest: efsWorker,
26-
cores: 1,
27-
logger,
28-
});
22+
const workerManager = await WorkerManager.createWorkerManager<EFSWorker>({
23+
workerFactory: () => new Worker(workerPath),
24+
manifest: efsWorker,
25+
cores: 1,
26+
logger,
27+
});
2928
const key = utils.generateKeySync(256);
3029
const plain100KiB = utils.getRandomBytesSync(1024 * 100);
3130
const cipher100KiB = await utils.encrypt(key, plain100KiB);
@@ -40,19 +39,19 @@ async function main() {
4039
b.add('encrypt 100 KiB of data with workers', async () => {
4140
const keyAB = utils.toArrayBuffer(key);
4241
const plainTextAB = utils.toArrayBuffer(plain100KiB);
43-
const {data: cipherTextAB} = await workerManager.methods.encrypt(
44-
{ key: keyAB, plainText: plainTextAB},
45-
[ keyAB, plainTextAB],
46-
)
42+
const { data: cipherTextAB } = await workerManager.methods.encrypt(
43+
{ key: keyAB, plainText: plainTextAB },
44+
[keyAB, plainTextAB],
45+
);
4746
utils.fromArrayBuffer(cipherTextAB);
4847
}),
4948
b.add('decrypt 100 KiB of data with workers', async () => {
5049
const keyAB = utils.toArrayBuffer(key);
5150
const cipherTextAB = cipher100KiB.slice(0);
5251
const { data: decrypted } = await workerManager.methods.decrypt(
53-
{key: keyAB, cipherText: cipherTextAB},
52+
{ key: keyAB, cipherText: cipherTextAB },
5453
[keyAB, cipherTextAB],
55-
)
54+
);
5655
if (decrypted != null) {
5756
utils.fromArrayBuffer(decrypted);
5857
}

benches/crypto_10KiB.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EFSWorker } from "#efsWorker.js";
1+
import type { EFSWorker } from '#efsWorker.js';
22
import os from 'node:os';
33
import path from 'node:path';
44
import url from 'node:url';
@@ -8,7 +8,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { WorkerManager } from '@matrixai/workers';
99
import { suiteCommon } from './utils/index.js';
1010
import * as utils from '#utils.js';
11-
import efsWorker from "#efsWorker.js";
11+
import efsWorker from '#efsWorker.js';
1212

1313
const logger = new Logger('crypto10KiB Bench', LogLevel.WARN, [
1414
new StreamHandler(),
@@ -19,13 +19,12 @@ const workerPath = path.join(filename, '../../dist/efsWorker');
1919
async function main() {
2020
const cores = os.cpus().length;
2121
logger.warn(`Cores: ${cores}`);
22-
const workerManager =
23-
await WorkerManager.createWorkerManager<EFSWorker>({
24-
workerFactory: () => new Worker(workerPath),
25-
manifest: efsWorker,
26-
cores: 1,
27-
logger,
28-
});
22+
const workerManager = await WorkerManager.createWorkerManager<EFSWorker>({
23+
workerFactory: () => new Worker(workerPath),
24+
manifest: efsWorker,
25+
cores: 1,
26+
logger,
27+
});
2928
const key = utils.generateKeySync(256);
3029
const plain10KiB = utils.getRandomBytesSync(1024 * 10);
3130
const cipher10KiB = await utils.encrypt(key, plain10KiB);
@@ -40,19 +39,19 @@ async function main() {
4039
b.add('encrypt 10 KiB of data with workers', async () => {
4140
const keyAB = utils.toArrayBuffer(key);
4241
const plainTextAB = utils.toArrayBuffer(plain10KiB);
43-
const {data: cipherTextAB} = await workerManager.methods.encrypt(
44-
{ key: keyAB, plainText: plainTextAB},
45-
[ keyAB, plainTextAB],
46-
)
42+
const { data: cipherTextAB } = await workerManager.methods.encrypt(
43+
{ key: keyAB, plainText: plainTextAB },
44+
[keyAB, plainTextAB],
45+
);
4746
utils.fromArrayBuffer(cipherTextAB);
4847
}),
4948
b.add('decrypt 10 KiB of data with workers', async () => {
5049
const keyAB = utils.toArrayBuffer(key);
5150
const cipherTextAB = cipher10KiB.slice(0);
5251
const { data: decrypted } = await workerManager.methods.decrypt(
53-
{key: keyAB, cipherText: cipherTextAB},
52+
{ key: keyAB, cipherText: cipherTextAB },
5453
[keyAB, cipherTextAB],
55-
)
54+
);
5655
if (decrypted != null) {
5756
utils.fromArrayBuffer(decrypted);
5857
}

benches/crypto_16KiB.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EFSWorker } from "#efsWorker.js";
1+
import type { EFSWorker } from '#efsWorker.js';
22
import os from 'node:os';
33
import path from 'node:path';
44
import url from 'node:url';
@@ -8,7 +8,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { WorkerManager } from '@matrixai/workers';
99
import { suiteCommon } from './utils/index.js';
1010
import * as utils from '#utils.js';
11-
import efsWorker from "#efsWorker.js";
11+
import efsWorker from '#efsWorker.js';
1212

1313
const logger = new Logger('crypto16KiB Bench', LogLevel.WARN, [
1414
new StreamHandler(),
@@ -19,13 +19,12 @@ const workerPath = path.join(filename, '../../dist/efsWorker');
1919
async function main() {
2020
const cores = os.cpus().length;
2121
logger.warn(`Cores: ${cores}`);
22-
const workerManager =
23-
await WorkerManager.createWorkerManager<EFSWorker>({
24-
workerFactory: () => new Worker(workerPath),
25-
manifest: efsWorker,
26-
cores: 1,
27-
logger,
28-
});
22+
const workerManager = await WorkerManager.createWorkerManager<EFSWorker>({
23+
workerFactory: () => new Worker(workerPath),
24+
manifest: efsWorker,
25+
cores: 1,
26+
logger,
27+
});
2928
const key = utils.generateKeySync(256);
3029
const plain16KiB = utils.getRandomBytesSync(1024 * 16);
3130
const cipher16KiB = await utils.encrypt(key, plain16KiB);
@@ -40,19 +39,19 @@ async function main() {
4039
b.add('encrypt 16 KiB of data with workers', async () => {
4140
const keyAB = utils.toArrayBuffer(key);
4241
const plainTextAB = utils.toArrayBuffer(plain16KiB);
43-
const {data: cipherTextAB} = await workerManager.methods.encrypt(
44-
{ key: keyAB, plainText: plainTextAB},
45-
[ keyAB, plainTextAB],
46-
)
42+
const { data: cipherTextAB } = await workerManager.methods.encrypt(
43+
{ key: keyAB, plainText: plainTextAB },
44+
[keyAB, plainTextAB],
45+
);
4746
utils.fromArrayBuffer(cipherTextAB);
4847
}),
4948
b.add('decrypt 16 KiB of data with workers', async () => {
5049
const keyAB = utils.toArrayBuffer(key);
5150
const cipherTextAB = cipher16KiB.slice(0);
5251
const { data: decrypted } = await workerManager.methods.decrypt(
53-
{key: keyAB, cipherText: cipherTextAB},
52+
{ key: keyAB, cipherText: cipherTextAB },
5453
[keyAB, cipherTextAB],
55-
)
54+
);
5655
if (decrypted != null) {
5756
utils.fromArrayBuffer(decrypted);
5857
}

benches/crypto_1KiB.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EFSWorker } from "#efsWorker.js";
1+
import type { EFSWorker } from '#efsWorker.js';
22
import os from 'node:os';
33
import path from 'node:path';
44
import url from 'node:url';
@@ -8,7 +8,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { WorkerManager } from '@matrixai/workers';
99
import { suiteCommon } from './utils/index.js';
1010
import * as utils from '#utils.js';
11-
import efsWorker from "#efsWorker.js";
11+
import efsWorker from '#efsWorker.js';
1212

1313
const logger = new Logger('crypto1KiB Bench', LogLevel.WARN, [
1414
new StreamHandler(),
@@ -19,13 +19,12 @@ const workerPath = path.join(filename, '../../dist/efsWorker');
1919
async function main() {
2020
const cores = os.cpus().length;
2121
logger.warn(`Cores: ${cores}`);
22-
const workerManager =
23-
await WorkerManager.createWorkerManager<EFSWorker>({
24-
workerFactory: () => new Worker(workerPath),
25-
manifest: efsWorker,
26-
cores,
27-
logger,
28-
});
22+
const workerManager = await WorkerManager.createWorkerManager<EFSWorker>({
23+
workerFactory: () => new Worker(workerPath),
24+
manifest: efsWorker,
25+
cores,
26+
logger,
27+
});
2928
const key = utils.generateKeySync(256);
3029
const plain1KiB = utils.getRandomBytesSync(1024);
3130
const cipher1KiB = await utils.encrypt(key, plain1KiB);
@@ -40,19 +39,19 @@ async function main() {
4039
b.add('encrypt 1 KiB of data with workers', async () => {
4140
const keyAB = utils.toArrayBuffer(key);
4241
const plainTextAB = utils.toArrayBuffer(plain1KiB);
43-
const {data: cipherTextAB} = await workerManager.methods.encrypt(
44-
{ key: keyAB, plainText: plainTextAB},
45-
[ keyAB, plainTextAB],
46-
)
42+
const { data: cipherTextAB } = await workerManager.methods.encrypt(
43+
{ key: keyAB, plainText: plainTextAB },
44+
[keyAB, plainTextAB],
45+
);
4746
utils.fromArrayBuffer(cipherTextAB);
4847
}),
4948
b.add('decrypt 1 KiB of data with workers', async () => {
5049
const keyAB = utils.toArrayBuffer(key);
5150
const cipherTextAB = cipher1KiB.slice(0);
5251
const { data: decrypted } = await workerManager.methods.decrypt(
53-
{key: keyAB, cipherText: cipherTextAB},
52+
{ key: keyAB, cipherText: cipherTextAB },
5453
[keyAB, cipherTextAB],
55-
)
54+
);
5655
if (decrypted != null) {
5756
utils.fromArrayBuffer(decrypted);
5857
}

benches/crypto_1MiB.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EFSWorker } from "#efsWorker.js";
1+
import type { EFSWorker } from '#efsWorker.js';
22
import os from 'node:os';
33
import path from 'node:path';
44
import url from 'node:url';
@@ -8,7 +8,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { WorkerManager } from '@matrixai/workers';
99
import { suiteCommon } from './utils/index.js';
1010
import * as utils from '#utils.js';
11-
import efsWorker from "#efsWorker.js";
11+
import efsWorker from '#efsWorker.js';
1212

1313
const logger = new Logger('crypto1MiB Bench', LogLevel.WARN, [
1414
new StreamHandler(),
@@ -19,13 +19,12 @@ const workerPath = path.join(filename, '../../dist/efsWorker');
1919
async function main() {
2020
const cores = os.cpus().length;
2121
logger.warn(`Cores: ${cores}`);
22-
const workerManager =
23-
await WorkerManager.createWorkerManager<EFSWorker>({
24-
workerFactory: () => new Worker(workerPath),
25-
manifest: efsWorker,
26-
cores: 1,
27-
logger,
28-
});
22+
const workerManager = await WorkerManager.createWorkerManager<EFSWorker>({
23+
workerFactory: () => new Worker(workerPath),
24+
manifest: efsWorker,
25+
cores: 1,
26+
logger,
27+
});
2928
const key = utils.generateKeySync(256);
3029
const plain1MiB = utils.getRandomBytesSync(1024 * 1024);
3130
const cipher1MiB = await utils.encrypt(key, plain1MiB);
@@ -40,19 +39,19 @@ async function main() {
4039
b.add('encrypt 1 MiB of data with workers', async () => {
4140
const keyAB = utils.toArrayBuffer(key);
4241
const plainTextAB = utils.toArrayBuffer(plain1MiB);
43-
const {data: cipherTextAB} = await workerManager.methods.encrypt(
44-
{ key: keyAB, plainText: plainTextAB},
45-
[ keyAB, plainTextAB],
46-
)
42+
const { data: cipherTextAB } = await workerManager.methods.encrypt(
43+
{ key: keyAB, plainText: plainTextAB },
44+
[keyAB, plainTextAB],
45+
);
4746
utils.fromArrayBuffer(cipherTextAB);
4847
}),
4948
b.add('decrypt 1 MiB of data with workers', async () => {
5049
const keyAB = utils.toArrayBuffer(key);
5150
const cipherTextAB = cipher1MiB.slice(0);
5251
const { data: decrypted } = await workerManager.methods.decrypt(
53-
{key: keyAB, cipherText: cipherTextAB},
52+
{ key: keyAB, cipherText: cipherTextAB },
5453
[keyAB, cipherTextAB],
55-
)
54+
);
5655
if (decrypted != null) {
5756
utils.fromArrayBuffer(decrypted);
5857
}

benches/crypto_24KiB.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EFSWorker } from "#efsWorker.js";
1+
import type { EFSWorker } from '#efsWorker.js';
22
import os from 'node:os';
33
import path from 'node:path';
44
import url from 'node:url';
@@ -8,7 +8,7 @@ import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
88
import { WorkerManager } from '@matrixai/workers';
99
import { suiteCommon } from './utils/index.js';
1010
import * as utils from '#utils.js';
11-
import efsWorker from "#efsWorker.js";
11+
import efsWorker from '#efsWorker.js';
1212

1313
const logger = new Logger('crypto24KiB Bench', LogLevel.WARN, [
1414
new StreamHandler(),
@@ -19,13 +19,12 @@ const workerPath = path.join(filename, '../../dist/efsWorker');
1919
async function main() {
2020
const cores = os.cpus().length;
2121
logger.warn(`Cores: ${cores}`);
22-
const workerManager =
23-
await WorkerManager.createWorkerManager<EFSWorker>({
24-
workerFactory: () => new Worker(workerPath),
25-
manifest: efsWorker,
26-
cores: 1,
27-
logger,
28-
});
22+
const workerManager = await WorkerManager.createWorkerManager<EFSWorker>({
23+
workerFactory: () => new Worker(workerPath),
24+
manifest: efsWorker,
25+
cores: 1,
26+
logger,
27+
});
2928
const key = utils.generateKeySync(256);
3029
const plain24KiB = utils.getRandomBytesSync(1024 * 24);
3130
const cipher24KiB = await utils.encrypt(key, plain24KiB);
@@ -40,19 +39,19 @@ async function main() {
4039
b.add('encrypt 24 KiB of data with workers', async () => {
4140
const keyAB = utils.toArrayBuffer(key);
4241
const plainTextAB = utils.toArrayBuffer(plain24KiB);
43-
const {data: cipherTextAB} = await workerManager.methods.encrypt(
44-
{ key: keyAB, plainText: plainTextAB},
45-
[ keyAB, plainTextAB],
46-
)
42+
const { data: cipherTextAB } = await workerManager.methods.encrypt(
43+
{ key: keyAB, plainText: plainTextAB },
44+
[keyAB, plainTextAB],
45+
);
4746
utils.fromArrayBuffer(cipherTextAB);
4847
}),
4948
b.add('decrypt 24 KiB of data with workers', async () => {
5049
const keyAB = utils.toArrayBuffer(key);
5150
const cipherTextAB = cipher24KiB.slice(0);
5251
const { data: decrypted } = await workerManager.methods.decrypt(
53-
{key: keyAB, cipherText: cipherTextAB},
52+
{ key: keyAB, cipherText: cipherTextAB },
5453
[keyAB, cipherTextAB],
55-
)
54+
);
5655
if (decrypted != null) {
5756
utils.fromArrayBuffer(decrypted);
5857
}

0 commit comments

Comments
 (0)