Skip to content

Commit

Permalink
moved lock benchmark to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Feb 26, 2020
1 parent 5013736 commit 9b94ab7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
40 changes: 40 additions & 0 deletions packages/server/tests/exchange-benchmark.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'jest-extended';
import 'reflect-metadata';
import {closeCreatedExchange, createExchange} from "./utils";

jest.setTimeout(30000);

test('test lock performance', async () => {
const locker = await createExchange();
const start = performance.now();

const count = 1_000;
for (let i = 0; i < count; i++) {
const lock1 = await locker.lock('test-perf-' + i);
await lock1.unlock();
}

//0.0035 takes native lock per item
//this takes 0.102, that's the price of communicating via webSockets
console.log(count, 'sequential locks took', performance.now() - start, 'ms', count * (1000 / (performance.now() - start)), 'op/s');
await locker.disconnect();
closeCreatedExchange();
});

test('test lock performance concurrent', async () => {
const locker = await createExchange();
const start = performance.now();

const count = 1_000;
const all: Promise<void>[] = [];
for (let i = 0; i < count; i++) {
all.push(locker.lock('test-perf-' + i).then((v) => {
return v.unlock();
}));
}

await Promise.all(all);
console.log(count, 'concurrent locks took', performance.now() - start, 'ms', count * (1000 / (performance.now() - start)), 'op/s');
await locker.disconnect();
closeCreatedExchange();
});
31 changes: 0 additions & 31 deletions packages/server/tests/exchange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,37 +148,6 @@ test('test lock timeout', async () => {
await locker.lock('my-timeout', 0, 1);
});

test('test lock performance', async () => {
const locker = await createExchange();
const start = performance.now();

const count = 1_000;
for (let i = 0; i < count; i++) {
const lock1 = await locker.lock('test-perf-' + i);
await lock1.unlock();
}

//0.0035 takes native lock per item
//this takes 0.102, that's the price of communicating via webSockets
console.log(count, 'sequential locks took', performance.now() - start, 'ms', count * (1000 / (performance.now() - start)), 'op/s');
});

test('test lock performance concurrent', async () => {
const locker = await createExchange();
const start = performance.now();

const count = 1_000;
const all: Promise<void>[] = [];
for (let i = 0; i < count; i++) {
all.push(locker.lock('test-perf-' + i).then((v) => {
return v.unlock();
}));
}

await Promise.all(all);
console.log(count, 'concurrent locks took', performance.now() - start, 'ms', count * (1000 / (performance.now() - start)), 'op/s');
});


test('test str2ab performance', async () => {
const count = 10_000;
Expand Down

0 comments on commit 9b94ab7

Please sign in to comment.