Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Commit

Permalink
Added benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed Jun 2, 2020
1 parent e0d6362 commit 532d1b2
Show file tree
Hide file tree
Showing 4 changed files with 2,154 additions and 68 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

.benchmark
50 changes: 37 additions & 13 deletions benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2019 DxOS.
//

const ram = require('random-access-memory');
const { createStorage } = require('@dxos/random-access-multi-storage');
const { Suite } = require('@dxos/benchmark-suite');

const { FeedStore } = require('.');
Expand All @@ -11,14 +11,16 @@ const range = n => [...Array(n).keys()];

(async () => {
const maxFeeds = 5;
const maxMessages = 10000;
const expectedMessages = count => {
if (count !== maxFeeds * maxMessages) {
const maxMessages = 1000;
const expectedMessages = maxFeeds * maxMessages;

const check = count => {
if (count !== expectedMessages) {
throw new Error('messages amount expected incorrect');
}
};

const fs = await FeedStore.create(ram, { feedOptions: { valueEncoding: 'utf8' } });
const fs = await FeedStore.create(createStorage('.benchmark'), { feedOptions: { valueEncoding: 'utf8' } });
const suite = new Suite(fs, { maxFeeds, maxMessages });

suite.beforeAll(() => {
Expand All @@ -39,7 +41,7 @@ const range = n => [...Array(n).keys()];
}));
});

suite.test('getBatch', async ({ context }) => {
suite.test('getBatch', async () => {
let count = 0;

await Promise.all(fs.getOpenFeeds().map(feed => {
Expand All @@ -52,38 +54,60 @@ const range = n => [...Array(n).keys()];
});
}));

expectedMessages(count);
check(count);
});

suite.test('createReadStream', async () => {
suite.test('createReadStream [batch=1]', async () => {
const stream = fs.createReadStream({ batch: 1 });
let count = 0;

await new Promise((resolve, reject) => {
stream.on('data', (data) => {
count++;
if (count === expectedMessages) resolve();
});
});

stream.destroy();

check(count);
});

suite.test('createReadStream [batch=100]', async () => {
const stream = fs.createReadStream({ batch: 100 });
let count = 0;

await new Promise((resolve, reject) => {
stream.on('data', (data) => {
count++;
if (count === maxMessages) resolve();
if (count === expectedMessages) resolve();
});
});

expectedMessages(count);
stream.destroy();

check(count);
});

suite.test('createBatchStream', async () => {
suite.test('createBatchStream [batch=100]', async () => {
const stream = fs.createBatchStream({ batch: 100 });
let count = 0;

await new Promise((resolve, reject) => {
stream.on('data', (data) => {
count += data.length;
if (count === maxMessages) resolve();
if (count === expectedMessages) resolve();
});
});

expectedMessages(count);
stream.destroy();

check(count);
});

const results = await suite.run();

suite.print(results);

process.exit(0);
})();
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"scripts": {
"build": "npm run clean && npm run build:babel",
"build:babel": "babel ./src --out-dir ./dist --ignore \"**/*.test.js\" --source-maps",
"benchmark": "npm run build && node benchmark.js",
"benchmark": "npm run build && npm run benchmark:node && npm run benchmark:browser",
"benchmark:node": "del-cli .benchmark && node benchmark.js",
"benchmark:browser": "browser-runner benchmark.js --timeout 0",
"clean": "del-cli dist",
"coverage": "npm test -- --coverage",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls",
Expand All @@ -36,7 +38,6 @@
"testEnvironment": "node"
},
"dependencies": {
"@dxos/benchmark-suite": "^1.0.0-beta.0",
"buffer-json-encoding": "^1.0.2",
"debug": "^4.1.1",
"end-of-stream": "^1.4.4",
Expand All @@ -60,6 +61,9 @@
"@babel/core": "^7.4.5",
"@babel/plugin-proposal-export-default-from": "^7.5.2",
"@babel/preset-env": "^7.4.5",
"@dxos/benchmark-suite": "^1.0.0-beta.1",
"@dxos/browser-runner": "^1.0.0-beta.8",
"@dxos/random-access-multi-storage": "^1.1.0-beta.3",
"babel-eslint": "^10.0.2",
"babel-jest": "^24.8.0",
"babel-plugin-add-module-exports": "^1.0.2",
Expand Down

0 comments on commit 532d1b2

Please sign in to comment.