-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid.ts
142 lines (117 loc) · 4.02 KB
/
id.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { bench, run } from "mitata";
import { Database } from "bun:sqlite";
import { Exabase } from "./src/index.ts";
const db1 = new Exabase({ endpoint: "", secretAccessKey: "" });
await db1.query({
table: "PACKET",
execute: {
createTable: true,
},
});
const db2 = Database.open("z/sql_file/Northwind_large.sqlite");
// const dataSizes = [9, 100, 1000, 10000, 100000]; // Test with varying data sizes
const dataSizes = [1, 10, 100]; // Test with varying data sizes
async function populateExabase(count: number): Promise<void> {
//generate dummy data, ensure the size match your exabase table scheme
const dummyData = Array.from({ length: count }).map((_, i) => ({
key: "item-" + i,
metadata: JSON.stringify({ time: Date.now() }),
}));
const packetCount = await db1.query({
table: "PACKET",
count: true,
});
if (packetCount !== dummyData.length) {
for (const item of dummyData) {
await db1.query({ table: "PACKET", insert: item });
}
}
}
async function benchmark(dataSize: number): Promise<void> {
//Recreate and populate according to size, so re-index and refresh.
await db1.query({
table: "PACKET",
execute: { dropTable: true },
});
await db1.query({
table: "PACKET",
execute: { createTable: true },
});
console.log(`Benchmarking with ${dataSize} items \n\n\n`);
await populateExabase(dataSize); // insert items or adjust data
//Exabase benchmarks for each scale:
// 1. SELECT all
const sqMany = {
table: "PACKET",
where: { "*": true },
get: true,
};
bench(`Exabase SELECT * (${dataSize})`, async () => {
await db1.query(sqMany);
});
// 2. SELECT with filter. Adjust field. Test index usage, when implemented
const sqFilter = {
table: "PACKET",
where: { "*": true },
get: true,
}; // Adjust filter value as needed
bench(`Exabase SELECT with filter (${dataSize})`, async () => {
await db1.query(sqFilter);
});
// 3. INSERT test. insert scheme should match Exabase expected fields or otherwise modify tests or database or adjust fields appropriately given Exabase fields expected to provide relevant performance measures.
const insertItem = {
LastName: "lastNameInsert",
FirstName: "firstNameInsert", // Generate suitable, scheme-compliant sample object
// ... populate rest
};
const sqInsert = { table: "PACKET", insert: insertItem };
bench(`Exabase INSERT (${dataSize})`, async () => await db1.query(sqInsert));
// 4. Update. Select first to be updated and generate change with correct fields to ensure scheme compatible, which depends on fields you expect in exabase..
if (dataSize > 0) {
const itemFirst = (
await db1.query({
table: "PACKET",
where: { "*": true },
get: true,
take: 1,
})
)[0];
const updatedItem = Object.assign({}, itemFirst, {
LastName: "UpdatedNameTest",
});
const sqUpdate = {
table: "PACKET",
update: updatedItem,
};
bench(`Exabase UPDATE (${dataSize})`, async () => {
await db1.query(sqUpdate);
});
}
// Sqlite setup (use larger, real db if desired or otherwise create mock equivalents for comparable schema and test).
const db2 = Database.open("z/sql_file/Northwind_large.sqlite");
bench(`SQLite SELECT * FROM "Employee" (${dataSize})`, () => {
db2.prepare(`SELECT * FROM "Employee"`).all();
});
//Test others..
// Example against sqlite. Generate equivalent benchmarks relative to relevant queries done on exabase, especially those exercising similar indexing strategies when and where supported since useful to identify any discrepancies and areas of practical focus where your benchmarks want shown specifically..
}
for (const size of dataSizes) {
await benchmark(size);
}
const sq = {
table: "PACKET",
where: { "*": true },
get: true,
};
{
bench('SELECT * FROM "Employee" Exabase', async () => {
await db1.query(sq);
});
}
const sq2 = db2.prepare(`SELECT * FROM "Employee"`);
{
bench('SELECT * FROM "Employee" sqlite', () => {
sq2.all();
});
}
run();