@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/dist/src/benchmarks.js
CHANGED
|
@@ -8,10 +8,9 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { field, vec } from "@dao-xyz/borsh";
|
|
11
|
-
import { BoolQuery, StringMatch, getIdProperty, id, } from "@peerbit/indexer-interface";
|
|
12
|
-
import B from "benchmark";
|
|
11
|
+
import { And, BoolQuery, Compare, IntegerCompare, Or, Query, Sort, StringMatch, getIdProperty, id, } from "@peerbit/indexer-interface";
|
|
13
12
|
import sodium from "libsodium-wrappers";
|
|
14
|
-
import
|
|
13
|
+
import * as B from "tinybench";
|
|
15
14
|
import { v4 as uuid } from "uuid";
|
|
16
15
|
const setup = async (properties, createIndicies, type = "transient") => {
|
|
17
16
|
await sodium.ready;
|
|
@@ -29,7 +28,7 @@ const setup = async (properties, createIndicies, type = "transient") => {
|
|
|
29
28
|
return { indices, store, directory };
|
|
30
29
|
};
|
|
31
30
|
let preFillCount = 2e4;
|
|
32
|
-
const
|
|
31
|
+
const stringBenchmark = async (createIndicies, type = "transient") => {
|
|
33
32
|
class StringDocument {
|
|
34
33
|
id;
|
|
35
34
|
string;
|
|
@@ -54,74 +53,41 @@ const strinbBenchmark = async (createIndicies, type = "transient") => {
|
|
|
54
53
|
await stringIndexPreFilled.store.put(new StringDocument(uuid(), i % 100 === 0 ? fixed : uuid()));
|
|
55
54
|
}
|
|
56
55
|
const stringIndexEmpty = await setup({ schema: StringDocument }, createIndicies, type);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
fn: async (deferred) => {
|
|
62
|
-
await stringIndexEmpty.store.put(new StringDocument(uuid(), uuid()));
|
|
63
|
-
deferred.resolve();
|
|
64
|
-
},
|
|
65
|
-
defer: true,
|
|
66
|
-
maxTime: 5,
|
|
56
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
57
|
+
await suite
|
|
58
|
+
.add("string put - " + type, async () => {
|
|
59
|
+
await stringIndexEmpty.store.put(new StringDocument(uuid(), uuid()));
|
|
67
60
|
})
|
|
68
|
-
.add("string query matching - " + type, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
await iterator.close();
|
|
75
|
-
deferred.resolve();
|
|
76
|
-
},
|
|
77
|
-
defer: true,
|
|
78
|
-
maxTime: 5,
|
|
61
|
+
.add("string query matching - " + type, async () => {
|
|
62
|
+
const iterator = stringIndexPreFilled.store.iterate({
|
|
63
|
+
query: new StringMatch({ key: "string", value: fixed }),
|
|
64
|
+
});
|
|
65
|
+
await iterator.next(10);
|
|
66
|
+
await iterator.close();
|
|
79
67
|
})
|
|
80
|
-
.add("string count matching - " + type, {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
deferred.resolve();
|
|
86
|
-
},
|
|
87
|
-
defer: true,
|
|
88
|
-
maxTime: 5,
|
|
68
|
+
.add("string count matching - " + type, async () => {
|
|
69
|
+
await stringIndexPreFilled.store.count({
|
|
70
|
+
query: new StringMatch({ key: "string", value: fixed }),
|
|
71
|
+
});
|
|
89
72
|
})
|
|
90
|
-
.add("string count no-matches - " + type, {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
deferred.resolve();
|
|
97
|
-
},
|
|
98
|
-
defer: true,
|
|
99
|
-
maxTime: 5,
|
|
100
|
-
})
|
|
101
|
-
.on("cycle", async (event) => {
|
|
102
|
-
// eslint-disable-next-line no-console
|
|
103
|
-
console.log(String(event.target));
|
|
104
|
-
})
|
|
105
|
-
.on("error", (err) => {
|
|
106
|
-
throw err;
|
|
107
|
-
})
|
|
108
|
-
.on("complete", async () => {
|
|
109
|
-
await stringIndexEmpty.indices.stop();
|
|
110
|
-
stringIndexEmpty.directory &&
|
|
111
|
-
fs.rmSync(stringIndexEmpty.directory, { recursive: true, force: true });
|
|
112
|
-
await stringIndexPreFilled.indices.stop();
|
|
113
|
-
stringIndexPreFilled.directory &&
|
|
114
|
-
fs.rmSync(stringIndexPreFilled.directory, {
|
|
115
|
-
recursive: true,
|
|
116
|
-
force: true,
|
|
117
|
-
});
|
|
118
|
-
done.resolve();
|
|
119
|
-
})
|
|
120
|
-
.on("error", (e) => {
|
|
121
|
-
done.reject(e);
|
|
73
|
+
.add("string count no-matches - " + type, async () => {
|
|
74
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
75
|
+
await stringIndexPreFilled.store.count({
|
|
76
|
+
query: new StringMatch({ key: "string", value: uuid() }),
|
|
77
|
+
});
|
|
122
78
|
})
|
|
123
79
|
.run();
|
|
124
|
-
|
|
80
|
+
await stringIndexEmpty.indices.stop();
|
|
81
|
+
stringIndexEmpty.directory &&
|
|
82
|
+
fs.rmSync(stringIndexEmpty.directory, { recursive: true, force: true });
|
|
83
|
+
await stringIndexPreFilled.indices.stop();
|
|
84
|
+
stringIndexPreFilled.directory &&
|
|
85
|
+
fs.rmSync(stringIndexPreFilled.directory, {
|
|
86
|
+
recursive: true,
|
|
87
|
+
force: true,
|
|
88
|
+
});
|
|
89
|
+
/* eslint-disable no-console */
|
|
90
|
+
console.table(suite.table());
|
|
125
91
|
};
|
|
126
92
|
const boolQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
127
93
|
class BoolQueryDocument {
|
|
@@ -147,54 +113,160 @@ const boolQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
|
147
113
|
await boolIndexPrefilled.store.put(new BoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false));
|
|
148
114
|
}
|
|
149
115
|
const boolIndexEmpty = await setup({ schema: BoolQueryDocument }, createIndicies, type);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
suite
|
|
153
|
-
.add(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
await iterator.close();
|
|
161
|
-
deferred.resolve();
|
|
162
|
-
},
|
|
163
|
-
defer: true,
|
|
164
|
-
maxTime: 5,
|
|
116
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
117
|
+
let fetch = 10;
|
|
118
|
+
await suite
|
|
119
|
+
.add(`bool query fetch ${fetch} - ${type}`, async () => {
|
|
120
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
121
|
+
const iterator = await boolIndexPrefilled.store.iterate({
|
|
122
|
+
query: new BoolQuery({ key: "bool", value: out }),
|
|
123
|
+
});
|
|
124
|
+
await iterator.next(10);
|
|
125
|
+
await iterator.close();
|
|
165
126
|
})
|
|
166
|
-
.add(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
},
|
|
171
|
-
defer: true,
|
|
172
|
-
maxTime: 5,
|
|
127
|
+
.add(`non bool query fetch ${fetch} - ${type}`, async () => {
|
|
128
|
+
const iterator = await boolIndexPrefilled.store.iterate();
|
|
129
|
+
await iterator.next(10);
|
|
130
|
+
await iterator.close();
|
|
173
131
|
})
|
|
174
|
-
.
|
|
175
|
-
|
|
176
|
-
|
|
132
|
+
.add(`non bool query fetch with sort ${fetch} - ${type}`, async () => {
|
|
133
|
+
const iterator = boolIndexPrefilled.store.iterate({
|
|
134
|
+
sort: [new Sort({ key: "id" })],
|
|
135
|
+
});
|
|
136
|
+
await iterator.next(10);
|
|
137
|
+
await iterator.close();
|
|
177
138
|
})
|
|
178
|
-
.
|
|
179
|
-
|
|
139
|
+
.add(`bool put - ${type}`, async () => {
|
|
140
|
+
await boolIndexEmpty.store.put(new BoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false));
|
|
180
141
|
})
|
|
181
|
-
.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
142
|
+
.run();
|
|
143
|
+
await boolIndexEmpty.indices.stop();
|
|
144
|
+
boolIndexEmpty.directory &&
|
|
145
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
146
|
+
await boolIndexPrefilled.indices.stop();
|
|
147
|
+
boolIndexPrefilled.directory &&
|
|
148
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
149
|
+
recursive: true,
|
|
150
|
+
force: true,
|
|
151
|
+
});
|
|
152
|
+
/* eslint-disable no-console */
|
|
153
|
+
console.table(suite.table());
|
|
154
|
+
};
|
|
155
|
+
const inequalityBenchmark = async (createIndicies, type = "transient") => {
|
|
156
|
+
class NumberQueryDocument {
|
|
157
|
+
id;
|
|
158
|
+
number;
|
|
159
|
+
constructor(id, number) {
|
|
160
|
+
this.id = id;
|
|
161
|
+
this.number = number;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
__decorate([
|
|
165
|
+
id({ type: "string" }),
|
|
166
|
+
__metadata("design:type", String)
|
|
167
|
+
], NumberQueryDocument.prototype, "id", void 0);
|
|
168
|
+
__decorate([
|
|
169
|
+
field({ type: "u32" }),
|
|
170
|
+
__metadata("design:type", Number)
|
|
171
|
+
], NumberQueryDocument.prototype, "number", void 0);
|
|
172
|
+
const fs = await import("fs");
|
|
173
|
+
const numberIndexPrefilled = await setup({ schema: NumberQueryDocument }, createIndicies, type);
|
|
174
|
+
let docCount = 10e4;
|
|
175
|
+
for (let i = 0; i < docCount; i++) {
|
|
176
|
+
await numberIndexPrefilled.store.put(new NumberQueryDocument(uuid(), i));
|
|
177
|
+
}
|
|
178
|
+
const boolIndexEmpty = await setup({ schema: NumberQueryDocument }, createIndicies, type);
|
|
179
|
+
// warmup
|
|
180
|
+
for (let i = 0; i < 1000; i++) {
|
|
181
|
+
const iterator = numberIndexPrefilled.store.iterate({
|
|
182
|
+
query: new IntegerCompare({
|
|
183
|
+
key: "number",
|
|
184
|
+
compare: Compare.Less,
|
|
185
|
+
value: 11,
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
await iterator.next(10);
|
|
189
|
+
await iterator.close();
|
|
190
|
+
}
|
|
191
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
192
|
+
let fetch = 10;
|
|
193
|
+
await suite
|
|
194
|
+
.add(`number query fetch ${fetch} - ${type}`, async () => {
|
|
195
|
+
const iterator = numberIndexPrefilled.store.iterate({
|
|
196
|
+
query: new IntegerCompare({
|
|
197
|
+
key: "number",
|
|
198
|
+
compare: Compare.Less,
|
|
199
|
+
value: 11,
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
await iterator.next(10);
|
|
203
|
+
await iterator.close();
|
|
204
|
+
})
|
|
205
|
+
.add(`non number query fetch ${fetch} - ${type}`, async () => {
|
|
206
|
+
const iterator = numberIndexPrefilled.store.iterate();
|
|
207
|
+
await iterator.next(10);
|
|
208
|
+
await iterator.close();
|
|
192
209
|
})
|
|
193
|
-
.
|
|
194
|
-
|
|
210
|
+
.add(`number put - ${type}`, async () => {
|
|
211
|
+
await boolIndexEmpty.store.put(new NumberQueryDocument(uuid(), Math.round(Math.random() * 0xffffffff)));
|
|
195
212
|
})
|
|
196
213
|
.run();
|
|
197
|
-
|
|
214
|
+
await boolIndexEmpty.indices.stop();
|
|
215
|
+
boolIndexEmpty.directory &&
|
|
216
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
217
|
+
await numberIndexPrefilled.indices.stop();
|
|
218
|
+
numberIndexPrefilled.directory &&
|
|
219
|
+
fs.rmSync(numberIndexPrefilled.directory, {
|
|
220
|
+
recursive: true,
|
|
221
|
+
force: true,
|
|
222
|
+
});
|
|
223
|
+
/* eslint-disable no-console */
|
|
224
|
+
console.table(suite.table());
|
|
225
|
+
};
|
|
226
|
+
const getBenchmark = async (createIndicies, type = "transient") => {
|
|
227
|
+
class BoolQueryDocument {
|
|
228
|
+
id;
|
|
229
|
+
bool;
|
|
230
|
+
constructor(id, bool) {
|
|
231
|
+
this.id = id;
|
|
232
|
+
this.bool = bool;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
__decorate([
|
|
236
|
+
id({ type: "string" }),
|
|
237
|
+
__metadata("design:type", String)
|
|
238
|
+
], BoolQueryDocument.prototype, "id", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
field({ type: "bool" }),
|
|
241
|
+
__metadata("design:type", Boolean)
|
|
242
|
+
], BoolQueryDocument.prototype, "bool", void 0);
|
|
243
|
+
const fs = await import("fs");
|
|
244
|
+
const boolIndexPrefilled = await setup({ schema: BoolQueryDocument }, createIndicies, type);
|
|
245
|
+
let docCount = preFillCount;
|
|
246
|
+
let ids = [];
|
|
247
|
+
for (let i = 0; i < docCount; i++) {
|
|
248
|
+
let id = uuid();
|
|
249
|
+
ids.push(id);
|
|
250
|
+
await boolIndexPrefilled.store.put(new BoolQueryDocument(id, Math.random() > 0.5 ? true : false));
|
|
251
|
+
}
|
|
252
|
+
const boolIndexEmpty = await setup({ schema: BoolQueryDocument }, createIndicies, type);
|
|
253
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
254
|
+
await suite
|
|
255
|
+
.add("get by id - " + type, async () => {
|
|
256
|
+
await boolIndexPrefilled.store.get(ids[Math.floor(Math.random() * ids.length)]);
|
|
257
|
+
})
|
|
258
|
+
.run();
|
|
259
|
+
await boolIndexEmpty.indices.stop();
|
|
260
|
+
boolIndexEmpty.directory &&
|
|
261
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
262
|
+
await boolIndexPrefilled.indices.stop();
|
|
263
|
+
boolIndexPrefilled.directory &&
|
|
264
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
265
|
+
recursive: true,
|
|
266
|
+
force: true,
|
|
267
|
+
});
|
|
268
|
+
/* eslint-disable no-console */
|
|
269
|
+
console.table(suite.table());
|
|
198
270
|
};
|
|
199
271
|
const nestedBoolQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
200
272
|
class Nested {
|
|
@@ -230,53 +302,31 @@ const nestedBoolQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
|
230
302
|
await boolIndexPrefilled.store.put(new NestedBoolQueryDocument(uuid(), i % 2 === 0 ? true : false));
|
|
231
303
|
}
|
|
232
304
|
const boolIndexEmpty = await setup({ schema: NestedBoolQueryDocument }, createIndicies, type);
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
.
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
await iterator.next(10);
|
|
243
|
-
await iterator.close();
|
|
244
|
-
deferred.resolve();
|
|
245
|
-
},
|
|
246
|
-
defer: true,
|
|
247
|
-
maxTime: 5,
|
|
248
|
-
async: true,
|
|
249
|
-
})
|
|
250
|
-
.add("nested bool put - " + type, {
|
|
251
|
-
fn: async (deferred) => {
|
|
252
|
-
await boolIndexEmpty.store.put(new NestedBoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false));
|
|
253
|
-
deferred.resolve();
|
|
254
|
-
},
|
|
255
|
-
defer: true,
|
|
256
|
-
maxTime: 5,
|
|
257
|
-
async: true,
|
|
258
|
-
})
|
|
259
|
-
.on("cycle", async (event) => {
|
|
260
|
-
// eslint-disable-next-line no-console
|
|
261
|
-
console.log(String(event.target));
|
|
305
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
306
|
+
await suite
|
|
307
|
+
.add("nested bool query - " + type, async () => {
|
|
308
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
309
|
+
const iterator = await boolIndexPrefilled.store.iterate({
|
|
310
|
+
query: new BoolQuery({ key: ["nested", "bool"], value: out }),
|
|
311
|
+
});
|
|
312
|
+
await iterator.next(10);
|
|
313
|
+
await iterator.close();
|
|
262
314
|
})
|
|
263
|
-
.
|
|
264
|
-
|
|
265
|
-
})
|
|
266
|
-
.on("complete", async () => {
|
|
267
|
-
await boolIndexEmpty.indices.stop();
|
|
268
|
-
boolIndexEmpty.directory &&
|
|
269
|
-
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
270
|
-
await boolIndexPrefilled.indices.stop();
|
|
271
|
-
boolIndexPrefilled.directory &&
|
|
272
|
-
fs.rmSync(boolIndexPrefilled.directory, {
|
|
273
|
-
recursive: true,
|
|
274
|
-
force: true,
|
|
275
|
-
});
|
|
276
|
-
done.resolve();
|
|
315
|
+
.add("nested bool put - " + type, async () => {
|
|
316
|
+
await boolIndexEmpty.store.put(new NestedBoolQueryDocument(uuid(), Math.random() > 0.5 ? true : false));
|
|
277
317
|
})
|
|
278
318
|
.run();
|
|
279
|
-
|
|
319
|
+
await boolIndexEmpty.indices.stop();
|
|
320
|
+
boolIndexEmpty.directory &&
|
|
321
|
+
fs.rmSync(boolIndexEmpty.directory, { recursive: true, force: true });
|
|
322
|
+
await boolIndexPrefilled.indices.stop();
|
|
323
|
+
boolIndexPrefilled.directory &&
|
|
324
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
325
|
+
recursive: true,
|
|
326
|
+
force: true,
|
|
327
|
+
});
|
|
328
|
+
/* eslint-disable no-console */
|
|
329
|
+
console.table(suite.table());
|
|
280
330
|
};
|
|
281
331
|
const shapedQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
282
332
|
class Nested {
|
|
@@ -313,66 +363,244 @@ const shapedQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
|
313
363
|
new Nested(i % 2 === 0 ? true : false),
|
|
314
364
|
]));
|
|
315
365
|
}
|
|
316
|
-
|
|
317
|
-
const suite = new B.Suite({ delay: 100 });
|
|
366
|
+
const suite = new B.Bench({ warmupIterations: 1000 });
|
|
318
367
|
let fetch = 10;
|
|
319
|
-
suite
|
|
320
|
-
.add("unshaped nested query - " + type, {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
368
|
+
await suite
|
|
369
|
+
.add("unshaped nested array query - " + type, async () => {
|
|
370
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
371
|
+
let iterator = await boolIndexPrefilled.store.iterate({
|
|
372
|
+
query: new BoolQuery({ key: ["nested", "bool"], value: out }),
|
|
373
|
+
});
|
|
374
|
+
const results = await iterator.next(fetch);
|
|
375
|
+
await iterator.close();
|
|
376
|
+
if (results.length !== fetch) {
|
|
377
|
+
throw new Error("Missing results");
|
|
378
|
+
}
|
|
379
|
+
})
|
|
380
|
+
.add("shaped nested array query - " + type, async () => {
|
|
381
|
+
const out = Math.random() > 0.5 ? true : false;
|
|
382
|
+
const iterator = boolIndexPrefilled.store.iterate({
|
|
383
|
+
query: new BoolQuery({ key: ["nested", "bool"], value: out }),
|
|
384
|
+
}, { shape: { id: true } });
|
|
385
|
+
const results = await iterator.next(fetch);
|
|
386
|
+
await iterator.close();
|
|
387
|
+
if (results.length !== fetch) {
|
|
388
|
+
throw new Error("Missing results");
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
.add("nested fetch without query - " + type, async () => {
|
|
392
|
+
const iterator = boolIndexPrefilled.store.iterate({}, { shape: { id: true } });
|
|
393
|
+
const results = await iterator.next(fetch);
|
|
394
|
+
await iterator.close();
|
|
395
|
+
if (results.length !== fetch) {
|
|
396
|
+
throw new Error("Missing results");
|
|
397
|
+
}
|
|
336
398
|
})
|
|
337
|
-
.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
399
|
+
.run();
|
|
400
|
+
await boolIndexPrefilled.indices.stop();
|
|
401
|
+
boolIndexPrefilled.directory &&
|
|
402
|
+
fs.rmSync(boolIndexPrefilled.directory, {
|
|
403
|
+
recursive: true,
|
|
404
|
+
force: true,
|
|
405
|
+
});
|
|
406
|
+
/* eslint-disable no-console */
|
|
407
|
+
console.table(suite.table());
|
|
408
|
+
};
|
|
409
|
+
const multiFieldQueryBenchmark = async (createIndicies, type = "transient") => {
|
|
410
|
+
class ReplicationRangeIndexableU32 {
|
|
411
|
+
id;
|
|
412
|
+
hash;
|
|
413
|
+
timestamp;
|
|
414
|
+
start1;
|
|
415
|
+
end1;
|
|
416
|
+
start2;
|
|
417
|
+
end2;
|
|
418
|
+
width;
|
|
419
|
+
mode;
|
|
420
|
+
constructor(properties) {
|
|
421
|
+
this.id = properties.id || uuid();
|
|
422
|
+
this.hash = properties.hash;
|
|
423
|
+
this.timestamp = properties.timestamp;
|
|
424
|
+
this.start1 = properties.start1;
|
|
425
|
+
this.end1 = properties.end1;
|
|
426
|
+
this.start2 = properties.start2;
|
|
427
|
+
this.end2 = properties.end2;
|
|
428
|
+
this.width = properties.width;
|
|
429
|
+
this.mode = properties.mode;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
__decorate([
|
|
433
|
+
id({ type: "string" }),
|
|
434
|
+
__metadata("design:type", String)
|
|
435
|
+
], ReplicationRangeIndexableU32.prototype, "id", void 0);
|
|
436
|
+
__decorate([
|
|
437
|
+
field({ type: "string" }),
|
|
438
|
+
__metadata("design:type", String)
|
|
439
|
+
], ReplicationRangeIndexableU32.prototype, "hash", void 0);
|
|
440
|
+
__decorate([
|
|
441
|
+
field({ type: "u64" }),
|
|
442
|
+
__metadata("design:type", BigInt)
|
|
443
|
+
], ReplicationRangeIndexableU32.prototype, "timestamp", void 0);
|
|
444
|
+
__decorate([
|
|
445
|
+
field({ type: "u32" }),
|
|
446
|
+
__metadata("design:type", Number)
|
|
447
|
+
], ReplicationRangeIndexableU32.prototype, "start1", void 0);
|
|
448
|
+
__decorate([
|
|
449
|
+
field({ type: "u32" }),
|
|
450
|
+
__metadata("design:type", Number)
|
|
451
|
+
], ReplicationRangeIndexableU32.prototype, "end1", void 0);
|
|
452
|
+
__decorate([
|
|
453
|
+
field({ type: "u32" }),
|
|
454
|
+
__metadata("design:type", Number)
|
|
455
|
+
], ReplicationRangeIndexableU32.prototype, "start2", void 0);
|
|
456
|
+
__decorate([
|
|
457
|
+
field({ type: "u32" }),
|
|
458
|
+
__metadata("design:type", Number)
|
|
459
|
+
], ReplicationRangeIndexableU32.prototype, "end2", void 0);
|
|
460
|
+
__decorate([
|
|
461
|
+
field({ type: "u32" }),
|
|
462
|
+
__metadata("design:type", Number)
|
|
463
|
+
], ReplicationRangeIndexableU32.prototype, "width", void 0);
|
|
464
|
+
__decorate([
|
|
465
|
+
field({ type: "u8" }),
|
|
466
|
+
__metadata("design:type", Number)
|
|
467
|
+
], ReplicationRangeIndexableU32.prototype, "mode", void 0);
|
|
468
|
+
const indexPrefilled = await setup({ schema: ReplicationRangeIndexableU32 }, createIndicies, type);
|
|
469
|
+
let docCount = 10e4; // This is very small, so we expect that the ops will be very fast (i.e a few amount to join)
|
|
470
|
+
for (let i = 0; i < docCount; i++) {
|
|
471
|
+
await indexPrefilled.store.put(new ReplicationRangeIndexableU32({
|
|
472
|
+
hash: uuid(),
|
|
473
|
+
timestamp: BigInt(i),
|
|
474
|
+
start1: i,
|
|
475
|
+
end1: i + 1,
|
|
476
|
+
start2: i + 2,
|
|
477
|
+
end2: i + 3,
|
|
478
|
+
width: i + 4,
|
|
479
|
+
mode: i % 3,
|
|
480
|
+
}));
|
|
481
|
+
}
|
|
482
|
+
const suite = new B.Bench({ warmupIterations: 500 });
|
|
483
|
+
let fetch = 10;
|
|
484
|
+
const fs = await import("fs");
|
|
485
|
+
const ors = [];
|
|
486
|
+
for (const point of [10, docCount - 4]) {
|
|
487
|
+
ors.push(new And([
|
|
488
|
+
new IntegerCompare({
|
|
489
|
+
key: "start1",
|
|
490
|
+
compare: Compare.LessOrEqual,
|
|
491
|
+
value: point,
|
|
492
|
+
}),
|
|
493
|
+
new IntegerCompare({
|
|
494
|
+
key: "end1",
|
|
495
|
+
compare: Compare.Greater,
|
|
496
|
+
value: point,
|
|
497
|
+
}),
|
|
498
|
+
]));
|
|
499
|
+
ors.push(new And([
|
|
500
|
+
new IntegerCompare({
|
|
501
|
+
key: "start2",
|
|
502
|
+
compare: Compare.LessOrEqual,
|
|
503
|
+
value: point,
|
|
504
|
+
}),
|
|
505
|
+
new IntegerCompare({
|
|
506
|
+
key: "end2",
|
|
507
|
+
compare: Compare.Greater,
|
|
508
|
+
value: point,
|
|
509
|
+
}),
|
|
510
|
+
]));
|
|
511
|
+
}
|
|
512
|
+
let complicatedQuery = [
|
|
513
|
+
new Or(ors) /* ,
|
|
514
|
+
new IntegerCompare({
|
|
515
|
+
key: "timestamp",
|
|
516
|
+
compare: Compare.Less,
|
|
517
|
+
value: 100
|
|
518
|
+
}) */,
|
|
519
|
+
];
|
|
520
|
+
const suites = [
|
|
521
|
+
/* {
|
|
522
|
+
query: [
|
|
523
|
+
new IntegerCompare({
|
|
524
|
+
key: "start1",
|
|
525
|
+
compare: Compare.LessOrEqual,
|
|
526
|
+
value: 5,
|
|
527
|
+
}),
|
|
528
|
+
new IntegerCompare({
|
|
529
|
+
key: "end1",
|
|
530
|
+
compare: Compare.Greater,
|
|
531
|
+
value: 5,
|
|
532
|
+
})
|
|
533
|
+
], name: "2-fields query"
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
query: [
|
|
537
|
+
|
|
538
|
+
new IntegerCompare({
|
|
539
|
+
key: "start1",
|
|
540
|
+
compare: Compare.LessOrEqual,
|
|
541
|
+
value: 5,
|
|
542
|
+
}),
|
|
543
|
+
new IntegerCompare({
|
|
544
|
+
key: "end1",
|
|
545
|
+
compare: Compare.Greater,
|
|
546
|
+
value: 5,
|
|
547
|
+
}),
|
|
548
|
+
new IntegerCompare({
|
|
549
|
+
key: "timestamp",
|
|
550
|
+
compare: Compare.Less,
|
|
551
|
+
value: 10,
|
|
552
|
+
}),
|
|
553
|
+
], name: "3-fields query"
|
|
554
|
+
}, */
|
|
555
|
+
{ query: complicatedQuery, name: "3-fields or query" },
|
|
556
|
+
];
|
|
557
|
+
suites.forEach(({ query, name }) => {
|
|
558
|
+
suite.add(`m-field ${name} query small fetch - ${type}`, async () => {
|
|
559
|
+
const iterator = await indexPrefilled.store.iterate({
|
|
560
|
+
query,
|
|
561
|
+
});
|
|
343
562
|
const results = await iterator.next(fetch);
|
|
344
563
|
await iterator.close();
|
|
345
|
-
if (results.length
|
|
346
|
-
throw new Error("
|
|
564
|
+
if (results.length === 0) {
|
|
565
|
+
throw new Error("No results");
|
|
347
566
|
}
|
|
348
|
-
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
async: true,
|
|
353
|
-
})
|
|
354
|
-
.on("cycle", async (event) => {
|
|
355
|
-
// eslint-disable-next-line no-console
|
|
356
|
-
console.log(String(event.target));
|
|
357
|
-
})
|
|
358
|
-
.on("error", (err) => {
|
|
359
|
-
done.reject(err);
|
|
360
|
-
})
|
|
361
|
-
.on("complete", async () => {
|
|
362
|
-
await boolIndexPrefilled.indices.stop();
|
|
363
|
-
boolIndexPrefilled.directory &&
|
|
364
|
-
fs.rmSync(boolIndexPrefilled.directory, {
|
|
365
|
-
recursive: true,
|
|
366
|
-
force: true,
|
|
567
|
+
});
|
|
568
|
+
/* .add(`m-field ${name} query all fetch - ${type}`, async () => {
|
|
569
|
+
const iterator = indexPrefilled.store.iterate({
|
|
570
|
+
query,
|
|
367
571
|
});
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
572
|
+
const results = await iterator.all();
|
|
573
|
+
|
|
574
|
+
if (results.length === 0) {
|
|
575
|
+
throw new Error("No results");
|
|
576
|
+
}
|
|
577
|
+
}) */
|
|
578
|
+
});
|
|
579
|
+
/* suite.add("m-field no query small fetch - " + type, async () => {
|
|
580
|
+
const iterator = await indexPrefilled.store.iterate();
|
|
581
|
+
const results = await iterator.next(fetch);
|
|
582
|
+
await iterator.close();
|
|
583
|
+
|
|
584
|
+
if (results.length === 0) {
|
|
585
|
+
throw new Error("No results");
|
|
586
|
+
}
|
|
587
|
+
}) */
|
|
588
|
+
await suite.run();
|
|
589
|
+
await indexPrefilled.indices.stop();
|
|
590
|
+
indexPrefilled.directory &&
|
|
591
|
+
fs.rmSync(indexPrefilled.directory, {
|
|
592
|
+
recursive: true,
|
|
593
|
+
force: true,
|
|
594
|
+
});
|
|
595
|
+
/* eslint-disable no-console */
|
|
596
|
+
console.table(suite.table());
|
|
372
597
|
};
|
|
373
598
|
export const benchmarks = async (createIndicies, type = "transient") => {
|
|
374
|
-
await
|
|
599
|
+
await inequalityBenchmark(createIndicies, type);
|
|
600
|
+
await multiFieldQueryBenchmark(createIndicies, type);
|
|
601
|
+
await stringBenchmark(createIndicies, type);
|
|
375
602
|
await shapedQueryBenchmark(createIndicies, type);
|
|
603
|
+
await getBenchmark(createIndicies, type);
|
|
376
604
|
await boolQueryBenchmark(createIndicies, type);
|
|
377
605
|
await nestedBoolQueryBenchmark(createIndicies, type);
|
|
378
606
|
};
|