Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CMCDragonkai committed Jul 4, 2023
1 parent 16333d6 commit c494b34
Show file tree
Hide file tree
Showing 15 changed files with 627 additions and 12 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/codesee-arch-diagram.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This workflow was added by CodeSee. Learn more at https://codesee.io/
# This is v2.0 of this workflow file
on:
push:
branches:
- staging
pull_request_target:
types: [opened, synchronize, reopened]

name: CodeSee

permissions: read-all

jobs:
codesee:
runs-on: ubuntu-latest
continue-on-error: true
name: Analyze the repo with CodeSee
steps:
- uses: Codesee-io/codesee-action@v2
with:
codesee-token: ${{ secrets.CODESEE_ARCH_DIAG_API_TOKEN }}
codesee-url: https://app.codesee.io
47 changes: 47 additions & 0 deletions benches/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env ts-node

import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
import tableNotIndexed from './table_not_indexed';
import tableIndexed from './table_indexed';
import tableDerived from './table_derived';

async function main(): Promise<void> {
await fs.promises.mkdir(path.join(__dirname, 'results'), { recursive: true });
await tableNotIndexed();
await tableIndexed();
await tableDerived();
const resultFilenames = await fs.promises.readdir(
path.join(__dirname, 'results'),
);
const metricsFile = await fs.promises.open(
path.join(__dirname, 'results', 'metrics.txt'),
'w',
);
let concatenating = false;
for (const resultFilename of resultFilenames) {
if (/.+_metrics\.txt$/.test(resultFilename)) {
const metricsData = await fs.promises.readFile(
path.join(__dirname, 'results', resultFilename),
);
if (concatenating) {
await metricsFile.write('\n');
}
await metricsFile.write(metricsData);
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'),
JSON.stringify(systemData, null, 2),
);
}

void main();
Empty file added benches/results/metrics.txt
Empty file.
41 changes: 41 additions & 0 deletions benches/results/system.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"cpu": {
"manufacturer": "AMD",
"brand": "Ryzen 7 2700X Eight-Core Processor",
"vendor": "AMD",
"family": "23",
"model": "8",
"stepping": "2",
"revision": "",
"voltage": "",
"speed": 3.7,
"speedMin": 2.2,
"speedMax": 3.7,
"governor": "performance",
"cores": 16,
"physicalCores": 8,
"performanceCores": 8,
"efficiencyCores": 0,
"processors": 1,
"socket": "",
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev sev_es",
"virtualization": true,
"cache": {
"l1d": 262144,
"l1i": 524288,
"l2": 4194304,
"l3": 16777216
}
},
"osInfo": {
"platform": "linux",
"distro": "nixos",
"release": "22.11",
"kernel": "6.1.23",
"arch": "x64"
},
"system": {
"model": "System Product Name",
"manufacturer": "System manufacturer"
}
}
41 changes: 41 additions & 0 deletions benches/table_derived.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'path';
import b from 'benny';
import Table from '@';
import { suiteCommon } from './utils';

async function main() {
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
b.add('insert', () => {
const t = new Table(['a', 'b', 'c', 'd'], [['a', 'b', 'c', 'd']]);
return () => {
t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
};
}),
b.add('delete row', () => {
const t = new Table(['a', 'b', 'c', 'd'], [['a', 'b', 'c', 'd']]);
const rI = t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
return () => {
t.deleteRow(rI);
};
}),
b.add('get where rows - 100', () => {
const t = new Table(['a', 'b', 'c', 'd'], [['a', 'b', 'c', 'd']]);
for (let i = 0; i < 100; i++) {
t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
}
return () => {
const rIs = t.whereRows(['a', 'b', 'c', 'd'], [1, 2, 3, 4]);
rIs.map((rI) => t.getRow(rI));
};
}),
...suiteCommon,
);
return summary;
}

if (require.main === module) {
void main();
}

export default main;
41 changes: 41 additions & 0 deletions benches/table_indexed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'path';
import b from 'benny';
import Table from '@';
import { suiteCommon } from './utils';

async function main() {
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
b.add('insert', () => {
const t = new Table(['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd']);
return () => {
t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
};
}),
b.add('delete row', () => {
const t = new Table(['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd']);
const rI = t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
return () => {
t.deleteRow(rI);
};
}),
b.add('get where rows - 100', () => {
const t = new Table(['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd']);
for (let i = 0; i < 100; i++) {
t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
}
return () => {
const rIs = t.whereRows('a', 1);
rIs.map((rI) => t.getRow(rI));
};
}),
...suiteCommon,
);
return summary;
}

if (require.main === module) {
void main();
}

export default main;
41 changes: 41 additions & 0 deletions benches/table_not_indexed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'path';
import b from 'benny';
import Table from '@';
import { suiteCommon } from './utils';

async function main() {
const summary = await b.suite(
path.basename(__filename, path.extname(__filename)),
b.add('insert row', () => {
const t = new Table(['a', 'b', 'c', 'd']);
return () => {
t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
};
}),
b.add('delete row', () => {
const t = new Table(['a', 'b', 'c', 'd']);
const rI = t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
return () => {
t.deleteRow(rI);
};
}),
b.add('get where rows - 100', () => {
const t = new Table(['a', 'b', 'c', 'd']);
for (let i = 0; i < 100; i++) {
t.insertRow({ a: 1, b: 2, c: 3, d: 4 });
}
return () => {
const rIs = t.whereRows('a', 1, true);
rIs.map((rI) => t.getRow(rI));
};
}),
...suiteCommon,
);
return summary;
}

if (require.main === module) {
void main();
}

export default main;
61 changes: 61 additions & 0 deletions benches/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import fs from 'fs';
import path from 'path';
import b from 'benny';
import { codeBlock } from 'common-tags';
import packageJson from '../package.json';

const suiteCommon = [
b.cycle(),
b.complete(),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
version: packageJson.version,
details: true,
}),
b.save({
file: (summary) => summary.name,
folder: path.join(__dirname, '../results'),
version: packageJson.version,
format: 'chart.html',
}),
b.complete((summary) => {
const filePath = path.join(
__dirname,
'../results',
summary.name + '_metrics.txt',
);
fs.writeFileSync(
filePath,
codeBlock`
# TYPE ${summary.name}_ops gauge
${summary.results
.map(
(result) =>
`${summary.name}_ops{name="${result.name}"} ${result.ops}`,
)
.join('\n')}
# TYPE ${summary.name}_margin gauge
${summary.results
.map(
(result) =>
`${summary.name}_margin{name="${result.name}"} ${result.margin}`,
)
.join('\n')}
# TYPE ${summary.name}_samples counter
${summary.results
.map(
(result) =>
`${summary.name}_samples{name="${result.name}"} ${result.samples}`,
)
.join('\n')}
` + '\n',
);
// eslint-disable-next-line no-console
console.log('\nSaved to:', path.resolve(filePath));
}),
];

export { suiteCommon };
Loading

0 comments on commit c494b34

Please sign in to comment.