@wxn0brp/db-benchmark 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/package.json +34 -5
- package/src/custom/dir-index.ts +7 -0
- package/src/custom/sqlite.ts +41 -0
- package/src/db.ts +13 -0
- package/src/generate-static.ts +35 -0
- package/src/generate.ts +50 -0
- package/src/index.ts +31 -0
- package/src/large.ts +107 -0
- package/src/local/args.ts +63 -0
- package/src/local/cloud.ts +143 -0
- package/src/local/compare.ts +159 -0
- package/src/local/display.ts +84 -0
- package/src/local/index.ts +113 -0
- package/src/page/cache.ts +33 -0
- package/src/page/compare.ts +435 -0
- package/src/page/index.ts +113 -0
- package/src/page/local.ts +188 -0
- package/src/page/summary.ts +164 -0
- package/src/page/tables.ts +212 -0
- package/src/page/types.ts +33 -0
- package/src/page/utils.ts +58 -0
- package/src/page/var.ts +31 -0
- package/src/run.ts +25 -0
- package/src/small.ts +95 -0
- package/src/utils.ts +71 -0
package/src/small.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Collection } from "@wxn0brp/db-core/helpers/collection";
|
|
2
|
+
import { generateUsers } from "./generate";
|
|
3
|
+
import { bench, type BenchResult } from "./run";
|
|
4
|
+
|
|
5
|
+
const COUNT = 10_000;
|
|
6
|
+
|
|
7
|
+
export async function benchmarkSmall(col: Collection): Promise<BenchResult[]> {
|
|
8
|
+
const results: BenchResult[] = [];
|
|
9
|
+
const userData = generateUsers(COUNT);
|
|
10
|
+
const ids: string[] = [];
|
|
11
|
+
|
|
12
|
+
results.push(
|
|
13
|
+
await bench(
|
|
14
|
+
"add-small",
|
|
15
|
+
async () => {
|
|
16
|
+
for (const u of userData) {
|
|
17
|
+
const doc = await col.add(u);
|
|
18
|
+
ids.push(doc._id);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
COUNT,
|
|
22
|
+
),
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const firstId = ids[0];
|
|
26
|
+
const midId = ids[Math.floor(ids.length / 2)];
|
|
27
|
+
const lastId = ids[ids.length - 1];
|
|
28
|
+
|
|
29
|
+
results.push(
|
|
30
|
+
await bench("findOne-small", () =>
|
|
31
|
+
col.findOne({
|
|
32
|
+
_id: firstId,
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
results.push(
|
|
37
|
+
await bench("find-search-small", () =>
|
|
38
|
+
col.find({
|
|
39
|
+
isActive: true,
|
|
40
|
+
}),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
results.push(
|
|
44
|
+
await bench("find-paginated-small", () =>
|
|
45
|
+
col.find(
|
|
46
|
+
{},
|
|
47
|
+
{
|
|
48
|
+
limit: 100,
|
|
49
|
+
},
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
results.push(
|
|
54
|
+
await bench("updateOne-small", () =>
|
|
55
|
+
col.updateOne(
|
|
56
|
+
{
|
|
57
|
+
_id: midId,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
age: 99,
|
|
61
|
+
},
|
|
62
|
+
),
|
|
63
|
+
),
|
|
64
|
+
);
|
|
65
|
+
results.push(
|
|
66
|
+
await bench("update-search-small", () =>
|
|
67
|
+
col.update(
|
|
68
|
+
{
|
|
69
|
+
isActive: false,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
isActive: true,
|
|
73
|
+
},
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
results.push(
|
|
78
|
+
await bench("removeOne-small", () =>
|
|
79
|
+
col.removeOne({
|
|
80
|
+
_id: lastId,
|
|
81
|
+
}),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
results.push(
|
|
85
|
+
await bench("remove-search-small", () =>
|
|
86
|
+
col.remove({
|
|
87
|
+
$lt: {
|
|
88
|
+
age: 25,
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return results;
|
|
95
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ActionsBaseInterface } from "@wxn0brp/db-core/types/action";
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
import { type BenchResult } from "./run";
|
|
5
|
+
|
|
6
|
+
process.on("uncaughtException", err => {
|
|
7
|
+
console.error("Uncaught exception:", err);
|
|
8
|
+
process.exit(1);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
process.on("unhandledRejection", reason => {
|
|
12
|
+
console.error("Unhandled rejection:", reason);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export async function loadCustomSetup(
|
|
17
|
+
adapterName: string,
|
|
18
|
+
adapter: ActionsBaseInterface,
|
|
19
|
+
): Promise<() => Promise<void>> {
|
|
20
|
+
const setupPath = resolve(import.meta.dirname, "custom", `${adapterName}.js`);
|
|
21
|
+
let onAfterAdd = async () => {};
|
|
22
|
+
|
|
23
|
+
if (existsSync(setupPath)) {
|
|
24
|
+
console.log(`-> Using custom setup for ${adapterName}`);
|
|
25
|
+
const mod = await import(setupPath);
|
|
26
|
+
|
|
27
|
+
if (typeof mod.init === "function") {
|
|
28
|
+
await mod.init(adapter);
|
|
29
|
+
} else {
|
|
30
|
+
console.log(`-> No init function found for ${adapterName}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (typeof mod.onAfterAdd === "function") {
|
|
34
|
+
onAfterAdd = () => mod.onAfterAdd(adapter);
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
console.log(`-> No custom setup found for ${adapterName}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return onAfterAdd;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function writeResults(
|
|
44
|
+
file: string,
|
|
45
|
+
params: {
|
|
46
|
+
results: BenchResult[];
|
|
47
|
+
adapter: string;
|
|
48
|
+
coreVersion: string;
|
|
49
|
+
adapterVersion: string;
|
|
50
|
+
},
|
|
51
|
+
) {
|
|
52
|
+
const results = {
|
|
53
|
+
time: new Date().toISOString(),
|
|
54
|
+
os: process.platform,
|
|
55
|
+
arch: process.arch,
|
|
56
|
+
node: process?.version,
|
|
57
|
+
bun: globalThis.Bun?.version || "N/A",
|
|
58
|
+
adapter: params.adapter,
|
|
59
|
+
coreVersion: params.coreVersion,
|
|
60
|
+
adapterVersion: params.adapterVersion,
|
|
61
|
+
results: params.results,
|
|
62
|
+
};
|
|
63
|
+
if (existsSync(file)) {
|
|
64
|
+
const oldResults = JSON.parse(readFileSync(file, "utf-8"));
|
|
65
|
+
results.results = [
|
|
66
|
+
...oldResults.results,
|
|
67
|
+
...results.results,
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
writeFileSync(file, JSON.stringify(results, null, 2));
|
|
71
|
+
}
|