@peerbit/indexer-tests 1.1.3 → 1.1.4
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/dist/src/benchmarks.d.ts.map +1 -1
- package/dist/src/benchmarks.js +431 -203
- package/dist/src/benchmarks.js.map +1 -1
- package/dist/src/tests.d.ts.map +1 -1
- package/dist/src/tests.js +574 -65
- package/dist/src/tests.js.map +1 -1
- package/package.json +2 -2
- package/src/benchmarks.ts +512 -218
- package/src/tests.ts +678 -69
package/src/benchmarks.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { field, vec } from "@dao-xyz/borsh";
|
|
2
2
|
import {
|
|
3
|
+
And,
|
|
3
4
|
BoolQuery,
|
|
5
|
+
Compare,
|
|
4
6
|
type Index,
|
|
5
7
|
type IndexEngineInitProperties,
|
|
6
8
|
type Indices,
|
|
9
|
+
IntegerCompare,
|
|
10
|
+
Or,
|
|
11
|
+
Query,
|
|
12
|
+
Sort,
|
|
7
13
|
StringMatch,
|
|
8
14
|
getIdProperty,
|
|
9
15
|
id,
|
|
10
16
|
} from "@peerbit/indexer-interface";
|
|
11
|
-
import B from "benchmark";
|
|
12
17
|
import sodium from "libsodium-wrappers";
|
|
13
|
-
import
|
|
18
|
+
import * as B from "tinybench";
|
|
14
19
|
import { v4 as uuid } from "uuid";
|
|
15
20
|
|
|
16
21
|
const setup = async <T>(
|
|
@@ -35,7 +40,7 @@ const setup = async <T>(
|
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
let preFillCount = 2e4;
|
|
38
|
-
const
|
|
43
|
+
const stringBenchmark = async (
|
|
39
44
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
40
45
|
type: "transient" | "persist" = "transient",
|
|
41
46
|
) => {
|
|
@@ -73,77 +78,45 @@ const strinbBenchmark = async (
|
|
|
73
78
|
type,
|
|
74
79
|
);
|
|
75
80
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
fn: async (deferred: any) => {
|
|
81
|
-
await stringIndexEmpty.store.put(new StringDocument(uuid(), uuid()));
|
|
82
|
-
deferred.resolve();
|
|
83
|
-
},
|
|
84
|
-
defer: true,
|
|
85
|
-
maxTime: 5,
|
|
81
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
82
|
+
await suite
|
|
83
|
+
.add("string put - " + type, async () => {
|
|
84
|
+
await stringIndexEmpty.store.put(new StringDocument(uuid(), uuid()));
|
|
86
85
|
})
|
|
87
|
-
.add("string query matching - " + type, {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
await iterator.close();
|
|
94
|
-
deferred.resolve();
|
|
95
|
-
},
|
|
96
|
-
defer: true,
|
|
97
|
-
maxTime: 5,
|
|
86
|
+
.add("string query matching - " + type, async () => {
|
|
87
|
+
const iterator = stringIndexPreFilled.store.iterate({
|
|
88
|
+
query: new StringMatch({ key: "string", value: fixed }),
|
|
89
|
+
});
|
|
90
|
+
await iterator.next(10);
|
|
91
|
+
await iterator.close();
|
|
98
92
|
})
|
|
99
93
|
|
|
100
|
-
.add("string count matching - " + type, {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
deferred.resolve();
|
|
106
|
-
},
|
|
107
|
-
defer: true,
|
|
108
|
-
maxTime: 5,
|
|
94
|
+
.add("string count matching - " + type, async () => {
|
|
95
|
+
await stringIndexPreFilled.store.count({
|
|
96
|
+
query: new StringMatch({ key: "string", value: fixed }),
|
|
97
|
+
});
|
|
109
98
|
})
|
|
110
|
-
.add("string count no-matches - " + type, {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
deferred.resolve();
|
|
117
|
-
},
|
|
118
|
-
defer: true,
|
|
119
|
-
maxTime: 5,
|
|
120
|
-
})
|
|
121
|
-
.on("cycle", async (event: any) => {
|
|
122
|
-
// eslint-disable-next-line no-console
|
|
123
|
-
console.log(String(event.target));
|
|
124
|
-
})
|
|
125
|
-
.on("error", (err: any) => {
|
|
126
|
-
throw err;
|
|
127
|
-
})
|
|
128
|
-
.on("complete", async () => {
|
|
129
|
-
await stringIndexEmpty.indices.stop();
|
|
130
|
-
stringIndexEmpty.directory &&
|
|
131
|
-
fs.rmSync(stringIndexEmpty.directory, { recursive: true, force: true });
|
|
132
|
-
|
|
133
|
-
await stringIndexPreFilled.indices.stop();
|
|
134
|
-
stringIndexPreFilled.directory &&
|
|
135
|
-
fs.rmSync(stringIndexPreFilled.directory, {
|
|
136
|
-
recursive: true,
|
|
137
|
-
force: true,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
done.resolve();
|
|
141
|
-
})
|
|
142
|
-
.on("error", (e) => {
|
|
143
|
-
done.reject(e);
|
|
99
|
+
.add("string count no-matches - " + type, async () => {
|
|
100
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
101
|
+
await stringIndexPreFilled.store.count({
|
|
102
|
+
query: new StringMatch({ key: "string", value: uuid() }),
|
|
103
|
+
});
|
|
144
104
|
})
|
|
145
105
|
.run();
|
|
146
|
-
|
|
106
|
+
|
|
107
|
+
await stringIndexEmpty.indices.stop();
|
|
108
|
+
stringIndexEmpty.directory &&
|
|
109
|
+
fs.rmSync(stringIndexEmpty.directory, { recursive: true, force: true });
|
|
110
|
+
|
|
111
|
+
await stringIndexPreFilled.indices.stop();
|
|
112
|
+
stringIndexPreFilled.directory &&
|
|
113
|
+
fs.rmSync(stringIndexPreFilled.directory, {
|
|
114
|
+
recursive: true,
|
|
115
|
+
force: true,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/* eslint-disable no-console */
|
|
119
|
+
console.table(suite.table());
|
|
147
120
|
};
|
|
148
121
|
|
|
149
122
|
const boolQueryBenchmark = async (
|
|
@@ -183,58 +156,204 @@ const boolQueryBenchmark = async (
|
|
|
183
156
|
type,
|
|
184
157
|
);
|
|
185
158
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
suite
|
|
189
|
-
.add(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
await iterator.close();
|
|
197
|
-
deferred.resolve();
|
|
198
|
-
},
|
|
199
|
-
defer: true,
|
|
200
|
-
maxTime: 5,
|
|
159
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
160
|
+
let fetch = 10;
|
|
161
|
+
await suite
|
|
162
|
+
.add(`bool query fetch ${fetch} - ${type}`, async () => {
|
|
163
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
164
|
+
const iterator = await boolIndexPrefilled.store.iterate({
|
|
165
|
+
query: new BoolQuery({ key: "bool", value: out }),
|
|
166
|
+
});
|
|
167
|
+
await iterator.next(10);
|
|
168
|
+
await iterator.close();
|
|
201
169
|
})
|
|
202
|
-
.add(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
);
|
|
207
|
-
deferred.resolve();
|
|
208
|
-
},
|
|
209
|
-
defer: true,
|
|
210
|
-
maxTime: 5,
|
|
170
|
+
.add(`non bool query fetch ${fetch} - ${type}`, async () => {
|
|
171
|
+
const iterator = await boolIndexPrefilled.store.iterate();
|
|
172
|
+
await iterator.next(10);
|
|
173
|
+
await iterator.close();
|
|
211
174
|
})
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
175
|
+
|
|
176
|
+
.add(`non bool query fetch with sort ${fetch} - ${type}`, async () => {
|
|
177
|
+
const iterator = boolIndexPrefilled.store.iterate({
|
|
178
|
+
sort: [new Sort({ key: "id" })],
|
|
179
|
+
});
|
|
180
|
+
await iterator.next(10);
|
|
181
|
+
await iterator.close();
|
|
182
|
+
})
|
|
183
|
+
.add(`bool put - ${type}`, async () => {
|
|
184
|
+
await boolIndexEmpty.store.put(
|
|
185
|
+
new BoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false),
|
|
186
|
+
);
|
|
215
187
|
})
|
|
216
|
-
.
|
|
217
|
-
|
|
188
|
+
.run();
|
|
189
|
+
|
|
190
|
+
await boolIndexEmpty.indices.stop();
|
|
191
|
+
boolIndexEmpty.directory &&
|
|
192
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
193
|
+
|
|
194
|
+
await boolIndexPrefilled.indices.stop();
|
|
195
|
+
boolIndexPrefilled.directory &&
|
|
196
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
197
|
+
recursive: true,
|
|
198
|
+
force: true,
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
/* eslint-disable no-console */
|
|
202
|
+
console.table(suite.table());
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const inequalityBenchmark = async (
|
|
206
|
+
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
207
|
+
type: "transient" | "persist" = "transient",
|
|
208
|
+
) => {
|
|
209
|
+
class NumberQueryDocument {
|
|
210
|
+
@id({ type: "string" })
|
|
211
|
+
id: string;
|
|
212
|
+
|
|
213
|
+
@field({ type: "u32" })
|
|
214
|
+
number: number;
|
|
215
|
+
|
|
216
|
+
constructor(id: string, number: number) {
|
|
217
|
+
this.id = id;
|
|
218
|
+
this.number = number;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const fs = await import("fs");
|
|
223
|
+
|
|
224
|
+
const numberIndexPrefilled = await setup(
|
|
225
|
+
{ schema: NumberQueryDocument },
|
|
226
|
+
createIndicies,
|
|
227
|
+
type,
|
|
228
|
+
);
|
|
229
|
+
let docCount = 10e4;
|
|
230
|
+
for (let i = 0; i < docCount; i++) {
|
|
231
|
+
await numberIndexPrefilled.store.put(new NumberQueryDocument(uuid(), i));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const boolIndexEmpty = await setup(
|
|
235
|
+
{ schema: NumberQueryDocument },
|
|
236
|
+
createIndicies,
|
|
237
|
+
type,
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// warmup
|
|
241
|
+
for (let i = 0; i < 1000; i++) {
|
|
242
|
+
const iterator = numberIndexPrefilled.store.iterate({
|
|
243
|
+
query: new IntegerCompare({
|
|
244
|
+
key: "number",
|
|
245
|
+
compare: Compare.Less,
|
|
246
|
+
value: 11,
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
await iterator.next(10);
|
|
250
|
+
await iterator.close();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
254
|
+
let fetch = 10;
|
|
255
|
+
await suite
|
|
256
|
+
.add(`number query fetch ${fetch} - ${type}`, async () => {
|
|
257
|
+
const iterator = numberIndexPrefilled.store.iterate({
|
|
258
|
+
query: new IntegerCompare({
|
|
259
|
+
key: "number",
|
|
260
|
+
compare: Compare.Less,
|
|
261
|
+
value: 11,
|
|
262
|
+
}),
|
|
263
|
+
});
|
|
264
|
+
await iterator.next(10);
|
|
265
|
+
await iterator.close();
|
|
218
266
|
})
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
await boolIndexPrefilled.indices.stop();
|
|
225
|
-
boolIndexPrefilled.directory &&
|
|
226
|
-
fs.rmSync(boolIndexPrefilled.directory, {
|
|
227
|
-
recursive: true,
|
|
228
|
-
force: true,
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
done.resolve();
|
|
267
|
+
|
|
268
|
+
.add(`non number query fetch ${fetch} - ${type}`, async () => {
|
|
269
|
+
const iterator = numberIndexPrefilled.store.iterate();
|
|
270
|
+
await iterator.next(10);
|
|
271
|
+
await iterator.close();
|
|
232
272
|
})
|
|
233
|
-
|
|
234
|
-
|
|
273
|
+
|
|
274
|
+
.add(`number put - ${type}`, async () => {
|
|
275
|
+
await boolIndexEmpty.store.put(
|
|
276
|
+
new NumberQueryDocument(uuid(), Math.round(Math.random() * 0xffffffff)),
|
|
277
|
+
);
|
|
235
278
|
})
|
|
236
279
|
.run();
|
|
237
|
-
|
|
280
|
+
|
|
281
|
+
await boolIndexEmpty.indices.stop();
|
|
282
|
+
boolIndexEmpty.directory &&
|
|
283
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
284
|
+
|
|
285
|
+
await numberIndexPrefilled.indices.stop();
|
|
286
|
+
numberIndexPrefilled.directory &&
|
|
287
|
+
fs.rmSync(numberIndexPrefilled.directory, {
|
|
288
|
+
recursive: true,
|
|
289
|
+
force: true,
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
/* eslint-disable no-console */
|
|
293
|
+
console.table(suite.table());
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const getBenchmark = async (
|
|
297
|
+
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
298
|
+
type: "transient" | "persist" = "transient",
|
|
299
|
+
) => {
|
|
300
|
+
class BoolQueryDocument {
|
|
301
|
+
@id({ type: "string" })
|
|
302
|
+
id: string;
|
|
303
|
+
|
|
304
|
+
@field({ type: "bool" })
|
|
305
|
+
bool: boolean;
|
|
306
|
+
|
|
307
|
+
constructor(id: string, bool: boolean) {
|
|
308
|
+
this.id = id;
|
|
309
|
+
this.bool = bool;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const fs = await import("fs");
|
|
314
|
+
|
|
315
|
+
const boolIndexPrefilled = await setup(
|
|
316
|
+
{ schema: BoolQueryDocument },
|
|
317
|
+
createIndicies,
|
|
318
|
+
type,
|
|
319
|
+
);
|
|
320
|
+
let docCount = preFillCount;
|
|
321
|
+
let ids = [];
|
|
322
|
+
for (let i = 0; i < docCount; i++) {
|
|
323
|
+
let id = uuid();
|
|
324
|
+
ids.push(id);
|
|
325
|
+
await boolIndexPrefilled.store.put(
|
|
326
|
+
new BoolQueryDocument(id, Math.random() > 0.5 ? true : false),
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const boolIndexEmpty = await setup(
|
|
331
|
+
{ schema: BoolQueryDocument },
|
|
332
|
+
createIndicies,
|
|
333
|
+
type,
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
337
|
+
await suite
|
|
338
|
+
.add("get by id - " + type, async () => {
|
|
339
|
+
await boolIndexPrefilled.store.get(
|
|
340
|
+
ids[Math.floor(Math.random() * ids.length)],
|
|
341
|
+
);
|
|
342
|
+
})
|
|
343
|
+
.run();
|
|
344
|
+
await boolIndexEmpty.indices.stop();
|
|
345
|
+
boolIndexEmpty.directory &&
|
|
346
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
347
|
+
|
|
348
|
+
await boolIndexPrefilled.indices.stop();
|
|
349
|
+
boolIndexPrefilled.directory &&
|
|
350
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
351
|
+
recursive: true,
|
|
352
|
+
force: true,
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
/* eslint-disable no-console */
|
|
356
|
+
console.table(suite.table());
|
|
238
357
|
};
|
|
239
358
|
|
|
240
359
|
const nestedBoolQueryBenchmark = async (
|
|
@@ -284,60 +403,36 @@ const nestedBoolQueryBenchmark = async (
|
|
|
284
403
|
type,
|
|
285
404
|
);
|
|
286
405
|
|
|
287
|
-
|
|
288
|
-
const suite = new B.Suite({ delay: 100 });
|
|
406
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
289
407
|
|
|
290
|
-
suite
|
|
291
|
-
.add("nested bool query - " + type, {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
await iterator.close();
|
|
299
|
-
deferred.resolve();
|
|
300
|
-
},
|
|
301
|
-
defer: true,
|
|
302
|
-
maxTime: 5,
|
|
303
|
-
async: true,
|
|
408
|
+
await suite
|
|
409
|
+
.add("nested bool query - " + type, async () => {
|
|
410
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
411
|
+
const iterator = await boolIndexPrefilled.store.iterate({
|
|
412
|
+
query: new BoolQuery({ key: ["nested", "bool"], value: out }),
|
|
413
|
+
});
|
|
414
|
+
await iterator.next(10);
|
|
415
|
+
await iterator.close();
|
|
304
416
|
})
|
|
305
|
-
.add("nested bool put - " + type, {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
uuid(),
|
|
310
|
-
Math.random() > 0.5 ? true : false,
|
|
311
|
-
),
|
|
312
|
-
);
|
|
313
|
-
deferred.resolve();
|
|
314
|
-
},
|
|
315
|
-
defer: true,
|
|
316
|
-
maxTime: 5,
|
|
317
|
-
async: true,
|
|
318
|
-
})
|
|
319
|
-
.on("cycle", async (event: any) => {
|
|
320
|
-
// eslint-disable-next-line no-console
|
|
321
|
-
console.log(String(event.target));
|
|
322
|
-
})
|
|
323
|
-
.on("error", (err: any) => {
|
|
324
|
-
done.reject(err);
|
|
325
|
-
})
|
|
326
|
-
.on("complete", async () => {
|
|
327
|
-
await boolIndexEmpty.indices.stop();
|
|
328
|
-
boolIndexEmpty.directory &&
|
|
329
|
-
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
330
|
-
|
|
331
|
-
await boolIndexPrefilled.indices.stop();
|
|
332
|
-
boolIndexPrefilled.directory &&
|
|
333
|
-
fs.rmSync(boolIndexPrefilled.directory, {
|
|
334
|
-
recursive: true,
|
|
335
|
-
force: true,
|
|
336
|
-
});
|
|
337
|
-
done.resolve();
|
|
417
|
+
.add("nested bool put - " + type, async () => {
|
|
418
|
+
await boolIndexEmpty.store.put(
|
|
419
|
+
new NestedBoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false),
|
|
420
|
+
);
|
|
338
421
|
})
|
|
339
422
|
.run();
|
|
340
|
-
|
|
423
|
+
await boolIndexEmpty.indices.stop();
|
|
424
|
+
boolIndexEmpty.directory &&
|
|
425
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
426
|
+
|
|
427
|
+
await boolIndexPrefilled.indices.stop();
|
|
428
|
+
boolIndexPrefilled.directory &&
|
|
429
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
430
|
+
recursive: true,
|
|
431
|
+
force: true,
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
/* eslint-disable no-console */
|
|
435
|
+
console.table(suite.table());
|
|
341
436
|
};
|
|
342
437
|
|
|
343
438
|
const shapedQueryBenchmark = async (
|
|
@@ -383,73 +478,272 @@ const shapedQueryBenchmark = async (
|
|
|
383
478
|
);
|
|
384
479
|
}
|
|
385
480
|
|
|
386
|
-
|
|
387
|
-
const suite = new B.Suite({ delay: 100 });
|
|
481
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
388
482
|
let fetch = 10;
|
|
389
|
-
suite
|
|
390
|
-
.add("unshaped nested query - " + type, {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
deferred.resolve();
|
|
402
|
-
},
|
|
403
|
-
defer: true,
|
|
404
|
-
maxTime: 5,
|
|
405
|
-
async: true,
|
|
483
|
+
await suite
|
|
484
|
+
.add("unshaped nested array query - " + type, async () => {
|
|
485
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
486
|
+
let iterator = await boolIndexPrefilled.store.iterate({
|
|
487
|
+
query: new BoolQuery({ key: ["nested", "bool"], value: out }),
|
|
488
|
+
});
|
|
489
|
+
const results = await iterator.next(fetch);
|
|
490
|
+
await iterator.close();
|
|
491
|
+
if (results.length !== fetch) {
|
|
492
|
+
throw new Error("Missing results");
|
|
493
|
+
}
|
|
406
494
|
})
|
|
407
|
-
.add("shaped nested query - " + type, {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
{
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
deferred.resolve();
|
|
422
|
-
},
|
|
423
|
-
defer: true,
|
|
424
|
-
maxTime: 5,
|
|
425
|
-
async: true,
|
|
426
|
-
})
|
|
427
|
-
.on("cycle", async (event: any) => {
|
|
428
|
-
// eslint-disable-next-line no-console
|
|
429
|
-
console.log(String(event.target));
|
|
430
|
-
})
|
|
431
|
-
.on("error", (err: any) => {
|
|
432
|
-
done.reject(err);
|
|
495
|
+
.add("shaped nested array query - " + type, async () => {
|
|
496
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
497
|
+
const iterator = boolIndexPrefilled.store.iterate(
|
|
498
|
+
{
|
|
499
|
+
query: new BoolQuery({ key: ["nested", "bool"], value: out }),
|
|
500
|
+
},
|
|
501
|
+
{ shape: { id: true } },
|
|
502
|
+
);
|
|
503
|
+
const results = await iterator.next(fetch);
|
|
504
|
+
await iterator.close();
|
|
505
|
+
if (results.length !== fetch) {
|
|
506
|
+
throw new Error("Missing results");
|
|
507
|
+
}
|
|
433
508
|
})
|
|
434
|
-
.
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
509
|
+
.add("nested fetch without query - " + type, async () => {
|
|
510
|
+
const iterator = boolIndexPrefilled.store.iterate(
|
|
511
|
+
{},
|
|
512
|
+
{ shape: { id: true } },
|
|
513
|
+
);
|
|
514
|
+
const results = await iterator.next(fetch);
|
|
515
|
+
await iterator.close();
|
|
516
|
+
if (results.length !== fetch) {
|
|
517
|
+
throw new Error("Missing results");
|
|
518
|
+
}
|
|
442
519
|
})
|
|
443
520
|
.run();
|
|
444
|
-
|
|
521
|
+
|
|
522
|
+
await boolIndexPrefilled.indices.stop();
|
|
523
|
+
boolIndexPrefilled.directory &&
|
|
524
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
525
|
+
recursive: true,
|
|
526
|
+
force: true,
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
/* eslint-disable no-console */
|
|
530
|
+
console.table(suite.table());
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
const multiFieldQueryBenchmark = async (
|
|
534
|
+
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
535
|
+
type: "transient" | "persist" = "transient",
|
|
536
|
+
) => {
|
|
537
|
+
class ReplicationRangeIndexableU32 {
|
|
538
|
+
@id({ type: "string" })
|
|
539
|
+
id: string;
|
|
540
|
+
|
|
541
|
+
@field({ type: "string" })
|
|
542
|
+
hash: string;
|
|
543
|
+
|
|
544
|
+
@field({ type: "u64" })
|
|
545
|
+
timestamp: bigint;
|
|
546
|
+
|
|
547
|
+
@field({ type: "u32" })
|
|
548
|
+
start1!: number;
|
|
549
|
+
|
|
550
|
+
@field({ type: "u32" })
|
|
551
|
+
end1!: number;
|
|
552
|
+
|
|
553
|
+
@field({ type: "u32" })
|
|
554
|
+
start2!: number;
|
|
555
|
+
|
|
556
|
+
@field({ type: "u32" })
|
|
557
|
+
end2!: number;
|
|
558
|
+
|
|
559
|
+
@field({ type: "u32" })
|
|
560
|
+
width!: number;
|
|
561
|
+
|
|
562
|
+
@field({ type: "u8" })
|
|
563
|
+
mode: number;
|
|
564
|
+
|
|
565
|
+
constructor(properties: {
|
|
566
|
+
id?: string;
|
|
567
|
+
hash: string;
|
|
568
|
+
timestamp: bigint;
|
|
569
|
+
start1: number;
|
|
570
|
+
end1: number;
|
|
571
|
+
start2: number;
|
|
572
|
+
end2: number;
|
|
573
|
+
width: number;
|
|
574
|
+
mode: number;
|
|
575
|
+
}) {
|
|
576
|
+
this.id = properties.id || uuid();
|
|
577
|
+
this.hash = properties.hash;
|
|
578
|
+
this.timestamp = properties.timestamp;
|
|
579
|
+
this.start1 = properties.start1;
|
|
580
|
+
this.end1 = properties.end1;
|
|
581
|
+
this.start2 = properties.start2;
|
|
582
|
+
this.end2 = properties.end2;
|
|
583
|
+
this.width = properties.width;
|
|
584
|
+
this.mode = properties.mode;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
const indexPrefilled = await setup(
|
|
589
|
+
{ schema: ReplicationRangeIndexableU32 },
|
|
590
|
+
createIndicies,
|
|
591
|
+
type,
|
|
592
|
+
);
|
|
593
|
+
|
|
594
|
+
let docCount = 10e4; // This is very small, so we expect that the ops will be very fast (i.e a few amount to join)
|
|
595
|
+
for (let i = 0; i < docCount; i++) {
|
|
596
|
+
await indexPrefilled.store.put(
|
|
597
|
+
new ReplicationRangeIndexableU32({
|
|
598
|
+
hash: uuid(),
|
|
599
|
+
timestamp: BigInt(i),
|
|
600
|
+
start1: i,
|
|
601
|
+
end1: i + 1,
|
|
602
|
+
start2: i + 2,
|
|
603
|
+
end2: i + 3,
|
|
604
|
+
width: i + 4,
|
|
605
|
+
mode: i % 3,
|
|
606
|
+
}),
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
const suite = new B.Bench({ warmupIterations: 500 });
|
|
611
|
+
let fetch = 10;
|
|
612
|
+
|
|
613
|
+
const fs = await import("fs");
|
|
614
|
+
const ors: any[] = [];
|
|
615
|
+
for (const point of [10, docCount - 4]) {
|
|
616
|
+
ors.push(
|
|
617
|
+
new And([
|
|
618
|
+
new IntegerCompare({
|
|
619
|
+
key: "start1",
|
|
620
|
+
compare: Compare.LessOrEqual,
|
|
621
|
+
value: point,
|
|
622
|
+
}),
|
|
623
|
+
new IntegerCompare({
|
|
624
|
+
key: "end1",
|
|
625
|
+
compare: Compare.Greater,
|
|
626
|
+
value: point,
|
|
627
|
+
}),
|
|
628
|
+
]),
|
|
629
|
+
);
|
|
630
|
+
ors.push(
|
|
631
|
+
new And([
|
|
632
|
+
new IntegerCompare({
|
|
633
|
+
key: "start2",
|
|
634
|
+
compare: Compare.LessOrEqual,
|
|
635
|
+
value: point,
|
|
636
|
+
}),
|
|
637
|
+
new IntegerCompare({
|
|
638
|
+
key: "end2",
|
|
639
|
+
compare: Compare.Greater,
|
|
640
|
+
value: point,
|
|
641
|
+
}),
|
|
642
|
+
]),
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
let complicatedQuery = [
|
|
646
|
+
new Or(ors) /* ,
|
|
647
|
+
new IntegerCompare({
|
|
648
|
+
key: "timestamp",
|
|
649
|
+
compare: Compare.Less,
|
|
650
|
+
value: 100
|
|
651
|
+
}) */,
|
|
652
|
+
];
|
|
653
|
+
|
|
654
|
+
const suites: { query: Query[]; name: string }[] = [
|
|
655
|
+
/* {
|
|
656
|
+
query: [
|
|
657
|
+
new IntegerCompare({
|
|
658
|
+
key: "start1",
|
|
659
|
+
compare: Compare.LessOrEqual,
|
|
660
|
+
value: 5,
|
|
661
|
+
}),
|
|
662
|
+
new IntegerCompare({
|
|
663
|
+
key: "end1",
|
|
664
|
+
compare: Compare.Greater,
|
|
665
|
+
value: 5,
|
|
666
|
+
})
|
|
667
|
+
], name: "2-fields query"
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
query: [
|
|
671
|
+
|
|
672
|
+
new IntegerCompare({
|
|
673
|
+
key: "start1",
|
|
674
|
+
compare: Compare.LessOrEqual,
|
|
675
|
+
value: 5,
|
|
676
|
+
}),
|
|
677
|
+
new IntegerCompare({
|
|
678
|
+
key: "end1",
|
|
679
|
+
compare: Compare.Greater,
|
|
680
|
+
value: 5,
|
|
681
|
+
}),
|
|
682
|
+
new IntegerCompare({
|
|
683
|
+
key: "timestamp",
|
|
684
|
+
compare: Compare.Less,
|
|
685
|
+
value: 10,
|
|
686
|
+
}),
|
|
687
|
+
], name: "3-fields query"
|
|
688
|
+
}, */
|
|
689
|
+
{ query: complicatedQuery, name: "3-fields or query" },
|
|
690
|
+
];
|
|
691
|
+
suites.forEach(({ query, name }) => {
|
|
692
|
+
suite.add(`m-field ${name} query small fetch - ${type}`, async () => {
|
|
693
|
+
const iterator = await indexPrefilled.store.iterate({
|
|
694
|
+
query,
|
|
695
|
+
});
|
|
696
|
+
const results = await iterator.next(fetch);
|
|
697
|
+
await iterator.close();
|
|
698
|
+
|
|
699
|
+
if (results.length === 0) {
|
|
700
|
+
throw new Error("No results");
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
/* .add(`m-field ${name} query all fetch - ${type}`, async () => {
|
|
705
|
+
const iterator = indexPrefilled.store.iterate({
|
|
706
|
+
query,
|
|
707
|
+
});
|
|
708
|
+
const results = await iterator.all();
|
|
709
|
+
|
|
710
|
+
if (results.length === 0) {
|
|
711
|
+
throw new Error("No results");
|
|
712
|
+
}
|
|
713
|
+
}) */
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
/* suite.add("m-field no query small fetch - " + type, async () => {
|
|
717
|
+
const iterator = await indexPrefilled.store.iterate();
|
|
718
|
+
const results = await iterator.next(fetch);
|
|
719
|
+
await iterator.close();
|
|
720
|
+
|
|
721
|
+
if (results.length === 0) {
|
|
722
|
+
throw new Error("No results");
|
|
723
|
+
}
|
|
724
|
+
}) */
|
|
725
|
+
await suite.run();
|
|
726
|
+
|
|
727
|
+
await indexPrefilled.indices.stop();
|
|
728
|
+
indexPrefilled.directory &&
|
|
729
|
+
fs.rmSync(indexPrefilled.directory, {
|
|
730
|
+
recursive: true,
|
|
731
|
+
force: true,
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
/* eslint-disable no-console */
|
|
735
|
+
console.table(suite.table());
|
|
445
736
|
};
|
|
446
737
|
|
|
447
738
|
export const benchmarks = async (
|
|
448
739
|
createIndicies: (directory?: string) => Indices | Promise<Indices>,
|
|
449
740
|
type: "transient" | "persist" = "transient",
|
|
450
741
|
) => {
|
|
451
|
-
await
|
|
742
|
+
await inequalityBenchmark(createIndicies, type);
|
|
743
|
+
await multiFieldQueryBenchmark(createIndicies, type);
|
|
744
|
+
await stringBenchmark(createIndicies, type);
|
|
452
745
|
await shapedQueryBenchmark(createIndicies, type);
|
|
746
|
+
await getBenchmark(createIndicies, type);
|
|
453
747
|
await boolQueryBenchmark(createIndicies, type);
|
|
454
748
|
await nestedBoolQueryBenchmark(createIndicies, type);
|
|
455
749
|
};
|