Skip to content

Commit

Permalink
Updated benchmarks with sublevel creation benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Mar 23, 2022
1 parent 715169e commit bc12c0a
Show file tree
Hide file tree
Showing 10 changed files with 1,583 additions and 731 deletions.
3 changes: 1 addition & 2 deletions benches/DB1KiB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ const logger = new Logger('DB1KiB Bench', LogLevel.WARN, [new StreamHandler()]);

async function main() {
const dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'encryptedfs-benches-'),
path.join(os.tmpdir(), 'db-benches-'),
);
const dbPath = `${dataDir}/db`;
const db = await DB.createDB({ dbPath, logger });
await db.start();
const data0 = crypto.randomBytes(0);
const data1KiB = crypto.randomBytes(1024);
const summary = await b.suite(
Expand Down
3 changes: 1 addition & 2 deletions benches/DB1MiB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ const logger = new Logger('DB1MiB Bench', LogLevel.WARN, [new StreamHandler()]);

async function main() {
const dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'encryptedfs-benches-'),
path.join(os.tmpdir(), 'db-benches-'),
);
const dbPath = `${dataDir}/db`;
const db = await DB.createDB({ dbPath, logger });
await db.start();
const data0 = crypto.randomBytes(0);
const data1MiB = crypto.randomBytes(1024 * 1024);
const summary = await b.suite(
Expand Down
86 changes: 86 additions & 0 deletions benches/DBLevel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import os from 'os';
import path from 'path';
import fs from 'fs';
import b from 'benny';
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
import DB from '@/DB';
import packageJson from '../package.json';

const logger = new Logger('DBLevel Bench', LogLevel.WARN, [
new StreamHandler(),
]);

async function main() {
const dataDir = await fs.promises.mkdtemp(
path.join(os.tmpdir(), 'encryptedfs-benches-'),
);
const dbPath = `${dataDir}/db`;
const db = await DB.createDB({ dbPath, logger });
const summary = await b.suite(
'DBLevel',
b.add('create 1 sublevels', async () => {
let level;
for (let i = 0; i < 1; i++) {
level = await db.level(`level${i}`, level);
}
}),
b.add('create 2 sublevels', async () => {
let level;
for (let i = 0; i < 2; i++) {
level = await db.level(`level${i}`, level);
}
}),
b.add('create 3 sublevels', async () => {
let level;
for (let i = 0; i < 3; i++) {
level = await db.level(`level${i}`, level);
}
}),
b.add('create 4 sublevels', async () => {
let level;
for (let i = 0; i < 4; i++) {
level = await db.level(`level${i}`, level);
}
}),
b.add('get via sublevel', async () => {
await db.put(['level0'], 'hello', 'world');
return async () => {
const level = await db.level('level0');
await level.get('hello');
};
}),
b.add('get via key path concatenation', async () => {
await db.put(['level0'], 'hello', 'world');
return async () => {
await db.get(['level0'], 'hello');
};
}),
b.cycle(),
b.complete(),
b.save({
file: 'DBLevel',
folder: 'benches/results',
version: packageJson.version,
details: true,
}),
b.save({
file: 'DBLevel',
folder: 'benches/results',
format: 'chart.html',
}),
);
await db.stop();
await fs.promises.rm(dataDir, {
force: true,
recursive: true,
});
return summary;
}

if (require.main === module) {
(async () => {
await main();
})();
}

export default main;
2 changes: 2 additions & 0 deletions benches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import fs from 'fs';
import si from 'systeminformation';
import DB1KiBBench from './DB1KiB';
import DB1MiBBench from './DB1MiB';
import DBLevelBench from './DBLevel';

async function main(): Promise<void> {
await DB1KiBBench();
await DB1MiBBench();
await DBLevelBench();
const systemData = await si.get({
cpu: '*',
osInfo: 'platform, distro, release, kernel, arch',
Expand Down
10 changes: 5 additions & 5 deletions benches/results/DB1KiB.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</head>
<body>
<div style="max-width: 800px">
<canvas id="chart1641977642424" width="16" height="9"></canvas>
<canvas id="chart1648010273459" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -34,10 +34,10 @@

return chunked.map((chunk) => chunk.join("")).join(" ");
};
const ctx1641977642424 = document
.getElementById("chart1641977642424")
const ctx1648010273459 = document
.getElementById("chart1648010273459")
.getContext("2d");
const chart1641977642424 = new Chart(ctx1641977642424, {
const chart1648010273459 = new Chart(ctx1648010273459, {
type: "bar",
data: {
labels: [
Expand All @@ -48,7 +48,7 @@
],
datasets: [
{
data: [51174, 32018, 37253, 20855],
data: [50696, 32195, 35092, 17442],
backgroundColor: [
"rgba(63, 142, 252, 0.8)",
"rgba(116, 165, 127, 0.8)",
Expand Down
Loading

0 comments on commit bc12c0a

Please sign in to comment.