@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/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 pDefer from "p-defer";
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 strinbBenchmark = async (
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
- let done = pDefer();
77
- const suite = new B.Suite({ delay: 100 });
78
- suite
79
- .add("string put - " + type, {
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
- fn: async (deferred: any) => {
89
- const iterator = stringIndexPreFilled.store.iterate({
90
- query: new StringMatch({ key: "string", value: fixed }),
91
- });
92
- await iterator.next(10);
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
- fn: async (deferred: any) => {
102
- await stringIndexPreFilled.store.count({
103
- query: new StringMatch({ key: "string", value: fixed }),
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
- fn: async (deferred: any) => {
112
- const out = Math.random() > 0.5 ? true : false;
113
- await stringIndexPreFilled.store.count({
114
- query: new StringMatch({ key: "string", value: uuid() }),
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
- return done.promise;
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
- let done = pDefer();
187
- const suite = new B.Suite({ delay: 100 });
188
- suite
189
- .add("bool query - " + type, {
190
- fn: async (deferred: any) => {
191
- const out = Math.random() > 0.5 ? true : false;
192
- const iterator = await boolIndexPrefilled.store.iterate({
193
- query: new BoolQuery({ key: "bool", value: out }),
194
- });
195
- await iterator.next(10);
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("bool put - " + type, {
203
- fn: async (deferred: any) => {
204
- await boolIndexEmpty.store.put(
205
- new BoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false),
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
- .on("cycle", async (event: any) => {
213
- // eslint-disable-next-line no-console
214
- console.log(String(event.target));
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
- .on("error", (err: any) => {
217
- throw err;
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
- .on("complete", async () => {
220
- await boolIndexEmpty.indices.stop();
221
- boolIndexEmpty.directory &&
222
- fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
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
- .on("error", (e) => {
234
- done.reject(e);
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
- return done.promise;
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
- let done = pDefer();
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
- fn: async (deferred: any) => {
293
- const out = Math.random() > 0.5 ? true : false;
294
- const iterator = await boolIndexPrefilled.store.iterate({
295
- query: new BoolQuery({ key: ["nested", "bool"], value: out }),
296
- });
297
- await iterator.next(10);
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
- fn: async (deferred: any) => {
307
- await boolIndexEmpty.store.put(
308
- new NestedBoolQueryDocument(
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
- return done.promise;
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
- let done = pDefer();
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
- fn: async (deferred: any) => {
392
- const out = Math.random() > 0.5 ? true : false;
393
- let iterator = await boolIndexPrefilled.store.iterate({
394
- query: new BoolQuery({ key: ["nested", "bool"], value: out }),
395
- });
396
- const results = await iterator.next(fetch);
397
- await iterator.close();
398
- if (results.length !== fetch) {
399
- throw new Error("Missing results");
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
- fn: async (deferred: any) => {
409
- const out = Math.random() > 0.5 ? true : false;
410
- const iterator = await boolIndexPrefilled.store.iterate(
411
- {
412
- query: new BoolQuery({ key: ["nested", "bool"], value: out }),
413
- },
414
- { shape: { id: true } },
415
- );
416
- const results = await iterator.next(fetch);
417
- await iterator.close();
418
- if (results.length !== fetch) {
419
- throw new Error("Missing results");
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
- .on("complete", async () => {
435
- await boolIndexPrefilled.indices.stop();
436
- boolIndexPrefilled.directory &&
437
- fs.rmSync(boolIndexPrefilled.directory, {
438
- recursive: true,
439
- force: true,
440
- });
441
- done.resolve();
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
- return done.promise;
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 strinbBenchmark(createIndicies, type);
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
  };