castrum 0.7.0
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/Cargo.toml +73 -0
- package/README.md +432 -0
- package/bench.ts +3 -0
- package/castrum.linux-x64-gnu.node +0 -0
- package/index.ts +24 -0
- package/package.json +94 -0
- package/rust/batch.rs +195 -0
- package/rust/cookie_parser.rs +70 -0
- package/rust/cors.rs +263 -0
- package/rust/hashing.rs +164 -0
- package/rust/headers.rs +234 -0
- package/rust/hmac_sha256.rs +113 -0
- package/rust/http_parser.rs +132 -0
- package/rust/ingress.rs +616 -0
- package/rust/ingress_constants.rs +89 -0
- package/rust/ip_trust.rs +185 -0
- package/rust/json_ops.rs +66 -0
- package/rust/json_patch_ops.rs +25 -0
- package/rust/json_schema.rs +151 -0
- package/rust/json_ser.rs +429 -0
- package/rust/lib.rs +48 -0
- package/rust/method.rs +141 -0
- package/rust/mime_lookup.rs +76 -0
- package/rust/output.rs +238 -0
- package/rust/proxy.rs +90 -0
- package/rust/query_parser.rs +141 -0
- package/rust/random_token.rs +52 -0
- package/rust/rate_limit.rs +203 -0
- package/rust/terminal.rs +95 -0
- package/rust/unit_tests.rs +843 -0
- package/rust/url_codec.rs +133 -0
- package/rust/util.rs +537 -0
- package/rust/validation.rs +107 -0
- package/rust/websocket.rs +23 -0
- package/src/baseline/index.ts +12 -0
- package/src/baseline/tasks/cookie.ts +22 -0
- package/src/baseline/tasks/hashing.ts +18 -0
- package/src/baseline/tasks/hmac.ts +38 -0
- package/src/baseline/tasks/http.ts +62 -0
- package/src/baseline/tasks/json-patch.ts +12 -0
- package/src/baseline/tasks/json.ts +50 -0
- package/src/baseline/tasks/mime.ts +5 -0
- package/src/baseline/tasks/query.ts +14 -0
- package/src/baseline/tasks/token.ts +15 -0
- package/src/baseline/tasks/url.ts +11 -0
- package/src/baseline/tasks/validation.ts +19 -0
- package/src/baseline/tasks/websocket.ts +14 -0
- package/src/bench/assert.ts +70 -0
- package/src/bench/checks.ts +227 -0
- package/src/bench/checksum.ts +27 -0
- package/src/bench/comparisons.ts +70 -0
- package/src/bench/concurrent-worker.ts +135 -0
- package/src/bench/fixtures.ts +233 -0
- package/src/bench/index.ts +2 -0
- package/src/bench/measure.ts +177 -0
- package/src/bench/now.ts +3 -0
- package/src/bench/report.ts +79 -0
- package/src/bench/run.ts +57 -0
- package/src/bench/tasks/complex.ts +232 -0
- package/src/bench/tasks/concurrent.ts +213 -0
- package/src/bench/tasks/cookie.ts +44 -0
- package/src/bench/tasks/hashing.ts +33 -0
- package/src/bench/tasks/hmac.ts +36 -0
- package/src/bench/tasks/http.ts +50 -0
- package/src/bench/tasks/index.ts +52 -0
- package/src/bench/tasks/json-patch.ts +21 -0
- package/src/bench/tasks/json.ts +33 -0
- package/src/bench/tasks/mime.ts +21 -0
- package/src/bench/tasks/query.ts +44 -0
- package/src/bench/tasks/stress.ts +142 -0
- package/src/bench/tasks/token.ts +20 -0
- package/src/bench/tasks/url.ts +34 -0
- package/src/bench/tasks/validation.ts +57 -0
- package/src/bench/tasks/websocket.ts +21 -0
- package/src/bench/types.ts +60 -0
- package/src/data/json-rows.ts +33 -0
- package/src/ingress/constants.ts +56 -0
- package/src/ingress/fast.ts +1082 -0
- package/src/ingress/handlers.ts +1202 -0
- package/src/ingress/index.ts +457 -0
- package/src/ingress/packed-input.ts +59 -0
- package/src/native/index.ts +207 -0
- package/src/rust-ffi/index.ts +555 -0
- package/src/shared/bytes.ts +36 -0
- package/src/shared/json.ts +18 -0
- package/src/shared/packed.ts +316 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import type { BenchFixtures, ComplexFixtures } from "../fixtures";
|
|
2
|
+
import type { ConcurrentBenchTask } from "../types";
|
|
3
|
+
|
|
4
|
+
export function concurrentTasks(
|
|
5
|
+
f: BenchFixtures,
|
|
6
|
+
c: ComplexFixtures,
|
|
7
|
+
): ConcurrentBenchTask[] {
|
|
8
|
+
return [
|
|
9
|
+
// ── JSON validation: medium concurrency ──
|
|
10
|
+
{
|
|
11
|
+
name: "native:json_valid_concurrent_10",
|
|
12
|
+
op: "native:json_valid",
|
|
13
|
+
payload: f.jsonPayload,
|
|
14
|
+
concurrency: 10,
|
|
15
|
+
iterationsPerSlot: 50,
|
|
16
|
+
warmupPerSlot: 5,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "rust:json_valid_concurrent_10",
|
|
20
|
+
op: "rust:json_valid",
|
|
21
|
+
payload: f.jsonPayload,
|
|
22
|
+
concurrency: 10,
|
|
23
|
+
iterationsPerSlot: 50,
|
|
24
|
+
warmupPerSlot: 5,
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// ── JSON validation: high concurrency ──
|
|
28
|
+
{
|
|
29
|
+
name: "native:json_valid_concurrent_50",
|
|
30
|
+
op: "native:json_valid",
|
|
31
|
+
payload: f.jsonPayload,
|
|
32
|
+
concurrency: 50,
|
|
33
|
+
iterationsPerSlot: 20,
|
|
34
|
+
warmupPerSlot: 2,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "rust:json_valid_concurrent_50",
|
|
38
|
+
op: "rust:json_valid",
|
|
39
|
+
payload: f.jsonPayload,
|
|
40
|
+
concurrency: 50,
|
|
41
|
+
iterationsPerSlot: 20,
|
|
42
|
+
warmupPerSlot: 2,
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
// ── HTTP parse burst ──
|
|
46
|
+
{
|
|
47
|
+
name: "native:http_parse_concurrent_20",
|
|
48
|
+
op: "native:http_parse",
|
|
49
|
+
payload: f.httpRaw,
|
|
50
|
+
concurrency: 20,
|
|
51
|
+
iterationsPerSlot: 50,
|
|
52
|
+
warmupPerSlot: 5,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "rust:http_parse_concurrent_20",
|
|
56
|
+
op: "rust:http_parse",
|
|
57
|
+
payload: f.httpRaw,
|
|
58
|
+
concurrency: 20,
|
|
59
|
+
iterationsPerSlot: 50,
|
|
60
|
+
warmupPerSlot: 5,
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
// ── HMAC burst ──
|
|
64
|
+
{
|
|
65
|
+
name: "native:hmac_sha256_concurrent_20",
|
|
66
|
+
op: "native:hmac_sha256",
|
|
67
|
+
payload: {
|
|
68
|
+
key: f.hmacKey,
|
|
69
|
+
data: f.hmacData,
|
|
70
|
+
},
|
|
71
|
+
concurrency: 20,
|
|
72
|
+
iterationsPerSlot: 30,
|
|
73
|
+
warmupPerSlot: 5,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "rust:hmac_sha256_concurrent_20",
|
|
77
|
+
op: "rust:hmac_sha256",
|
|
78
|
+
payload: {
|
|
79
|
+
key: f.hmacKey,
|
|
80
|
+
data: f.hmacData,
|
|
81
|
+
},
|
|
82
|
+
concurrency: 20,
|
|
83
|
+
iterationsPerSlot: 30,
|
|
84
|
+
warmupPerSlot: 5,
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
// ── Validation burst: email ──
|
|
88
|
+
{
|
|
89
|
+
name: "native:validate_email_concurrent_50",
|
|
90
|
+
op: "native:validate_email",
|
|
91
|
+
payload: f.emailOk,
|
|
92
|
+
concurrency: 50,
|
|
93
|
+
iterationsPerSlot: 40,
|
|
94
|
+
warmupPerSlot: 5,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "rust:validate_email_concurrent_50",
|
|
98
|
+
op: "rust:validate_email",
|
|
99
|
+
payload: f.emailOk,
|
|
100
|
+
concurrency: 50,
|
|
101
|
+
iterationsPerSlot: 40,
|
|
102
|
+
warmupPerSlot: 5,
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// ── Validation burst: uuid ──
|
|
106
|
+
{
|
|
107
|
+
name: "native:validate_uuid_concurrent_50",
|
|
108
|
+
op: "native:validate_uuid",
|
|
109
|
+
payload: f.uuidOk,
|
|
110
|
+
concurrency: 50,
|
|
111
|
+
iterationsPerSlot: 40,
|
|
112
|
+
warmupPerSlot: 5,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "rust:validate_uuid_concurrent_50",
|
|
116
|
+
op: "rust:validate_uuid",
|
|
117
|
+
payload: f.uuidOk,
|
|
118
|
+
concurrency: 50,
|
|
119
|
+
iterationsPerSlot: 40,
|
|
120
|
+
warmupPerSlot: 5,
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
// ── Query parse burst ──
|
|
124
|
+
{
|
|
125
|
+
name: "native:query_parse_concurrent_20",
|
|
126
|
+
op: "native:query_parse",
|
|
127
|
+
payload: f.queryStr,
|
|
128
|
+
concurrency: 20,
|
|
129
|
+
iterationsPerSlot: 50,
|
|
130
|
+
warmupPerSlot: 5,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: "rust:query_parse_concurrent_20",
|
|
134
|
+
op: "rust:query_parse",
|
|
135
|
+
payload: f.queryStr,
|
|
136
|
+
concurrency: 20,
|
|
137
|
+
iterationsPerSlot: 50,
|
|
138
|
+
warmupPerSlot: 5,
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
// ── Cookie parse burst ──
|
|
142
|
+
{
|
|
143
|
+
name: "native:cookie_parse_concurrent_20",
|
|
144
|
+
op: "native:cookie_parse",
|
|
145
|
+
payload: f.cookieStr,
|
|
146
|
+
concurrency: 20,
|
|
147
|
+
iterationsPerSlot: 50,
|
|
148
|
+
warmupPerSlot: 5,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "rust:cookie_parse_concurrent_20",
|
|
152
|
+
op: "rust:cookie_parse",
|
|
153
|
+
payload: f.cookieStr,
|
|
154
|
+
concurrency: 20,
|
|
155
|
+
iterationsPerSlot: 50,
|
|
156
|
+
warmupPerSlot: 5,
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
// ── CRC32 burst ──
|
|
160
|
+
{
|
|
161
|
+
name: "native:crc32_concurrent_20",
|
|
162
|
+
op: "native:crc32",
|
|
163
|
+
payload: f.crcInput,
|
|
164
|
+
concurrency: 20,
|
|
165
|
+
iterationsPerSlot: 100,
|
|
166
|
+
warmupPerSlot: 10,
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "rust:crc32_concurrent_20",
|
|
170
|
+
op: "rust:crc32",
|
|
171
|
+
payload: f.crcInput,
|
|
172
|
+
concurrency: 20,
|
|
173
|
+
iterationsPerSlot: 100,
|
|
174
|
+
warmupPerSlot: 10,
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
// ── JSON sum burst ──
|
|
178
|
+
{
|
|
179
|
+
name: "native:json_sum_concurrent_20",
|
|
180
|
+
op: "native:json_sum",
|
|
181
|
+
payload: f.jsonPayload,
|
|
182
|
+
concurrency: 20,
|
|
183
|
+
iterationsPerSlot: 20,
|
|
184
|
+
warmupPerSlot: 3,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "rust:json_sum_concurrent_20",
|
|
188
|
+
op: "rust:json_sum",
|
|
189
|
+
payload: f.jsonPayload,
|
|
190
|
+
concurrency: 20,
|
|
191
|
+
iterationsPerSlot: 20,
|
|
192
|
+
warmupPerSlot: 3,
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
// ── Batch JSON validation burst ──
|
|
196
|
+
{
|
|
197
|
+
name: "native:json_valid_batch_concurrent_10",
|
|
198
|
+
op: "native:json_valid_batch",
|
|
199
|
+
payload: c.batchJsonDocs,
|
|
200
|
+
concurrency: 10,
|
|
201
|
+
iterationsPerSlot: 20,
|
|
202
|
+
warmupPerSlot: 3,
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
name: "rust:json_valid_batch_concurrent_10",
|
|
206
|
+
op: "rust:json_valid_batch_packed",
|
|
207
|
+
payload: c.batchJsonDocs,
|
|
208
|
+
concurrency: 10,
|
|
209
|
+
iterationsPerSlot: 20,
|
|
210
|
+
warmupPerSlot: 3,
|
|
211
|
+
},
|
|
212
|
+
];
|
|
213
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import { pairsToObject, readPairsPacked } from "../../shared/packed";
|
|
4
|
+
import type { BenchFixtures } from "../fixtures";
|
|
5
|
+
import type { BenchTask } from "../types";
|
|
6
|
+
|
|
7
|
+
export function cookieTasks(f: BenchFixtures): BenchTask[] {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "native:cookie_parse",
|
|
11
|
+
run: () => native.nativeCookieParsePacked(f.cookieStr).byteLength,
|
|
12
|
+
iterations: 500,
|
|
13
|
+
warmup: 50,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "rust:cookie_parse",
|
|
17
|
+
run: () => rust.cookieParsePacked(f.cookieStr).byteLength,
|
|
18
|
+
iterations: 500,
|
|
19
|
+
warmup: 50,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "native:cookie_parse_pipeline",
|
|
23
|
+
run: () => {
|
|
24
|
+
const obj = pairsToObject(
|
|
25
|
+
readPairsPacked(native.nativeCookieParsePacked(f.cookieStr)),
|
|
26
|
+
);
|
|
27
|
+
return Object.keys(obj).length;
|
|
28
|
+
},
|
|
29
|
+
iterations: 300,
|
|
30
|
+
warmup: 30,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "rust:cookie_parse_pipeline",
|
|
34
|
+
run: () => {
|
|
35
|
+
const obj = pairsToObject(
|
|
36
|
+
readPairsPacked(rust.cookieParsePacked(f.cookieStr)),
|
|
37
|
+
);
|
|
38
|
+
return Object.keys(obj).length;
|
|
39
|
+
},
|
|
40
|
+
iterations: 300,
|
|
41
|
+
warmup: 30,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import type { BenchFixtures } from "../fixtures";
|
|
4
|
+
import type { BenchTask } from "../types";
|
|
5
|
+
|
|
6
|
+
export function hashingTasks(f: BenchFixtures): BenchTask[] {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
name: "native:crc32",
|
|
10
|
+
run: () => native.nativeCrc32(f.crcInput),
|
|
11
|
+
iterations: 1000,
|
|
12
|
+
warmup: 100,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "rust:crc32",
|
|
16
|
+
run: () => rust.crc32(f.crcInput),
|
|
17
|
+
iterations: 1000,
|
|
18
|
+
warmup: 100,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "native:fnv1a64",
|
|
22
|
+
run: () => native.nativeFnv1a64(f.crcInput),
|
|
23
|
+
iterations: 1000,
|
|
24
|
+
warmup: 100,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "rust:fnv1a64",
|
|
28
|
+
run: () => rust.fnv1a64(f.crcInput),
|
|
29
|
+
iterations: 1000,
|
|
30
|
+
warmup: 100,
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import type { BenchFixtures } from "../fixtures";
|
|
4
|
+
import type { BenchTask } from "../types";
|
|
5
|
+
|
|
6
|
+
export function hmacTasks(f: BenchFixtures): BenchTask[] {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
name: "native:hmac_sha256",
|
|
10
|
+
run: () => native.nativeHmacSha256(f.hmacKey, f.hmacData).byteLength,
|
|
11
|
+
iterations: 500,
|
|
12
|
+
warmup: 50,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "rust:hmac_sha256",
|
|
16
|
+
run: () => rust.hmacSha256(f.hmacKey, f.hmacData).byteLength,
|
|
17
|
+
iterations: 500,
|
|
18
|
+
warmup: 50,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "native:hmac_verify",
|
|
22
|
+
run: () =>
|
|
23
|
+
native.nativeHmacSha256Verify(f.hmacKey, f.hmacData, f.hmacSig)
|
|
24
|
+
? 1
|
|
25
|
+
: 0,
|
|
26
|
+
iterations: 500,
|
|
27
|
+
warmup: 50,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "rust:hmac_verify",
|
|
31
|
+
run: () => rust.hmacSha256Verify(f.hmacKey, f.hmacData, f.hmacSig),
|
|
32
|
+
iterations: 500,
|
|
33
|
+
warmup: 50,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import { readHttpPacked } from "../../shared/packed";
|
|
4
|
+
import type { BenchFixtures } from "../fixtures";
|
|
5
|
+
import type { BenchTask } from "../types";
|
|
6
|
+
|
|
7
|
+
export function httpTasks(f: BenchFixtures): BenchTask[] {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "native:http_parse",
|
|
11
|
+
run: () => native.nativeHttpParseRequestPacked(f.httpRaw).byteLength,
|
|
12
|
+
iterations: 500,
|
|
13
|
+
warmup: 50,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "rust:http_parse",
|
|
17
|
+
run: () => rust.httpParseRequestPacked(f.httpRaw).byteLength,
|
|
18
|
+
iterations: 500,
|
|
19
|
+
warmup: 50,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "native:http_parse_pipeline",
|
|
23
|
+
run: () => {
|
|
24
|
+
const parsed = readHttpPacked(
|
|
25
|
+
native.nativeHttpParseRequestPacked(f.httpRaw),
|
|
26
|
+
);
|
|
27
|
+
return (
|
|
28
|
+
parsed.method.length +
|
|
29
|
+
parsed.path.length +
|
|
30
|
+
Object.keys(parsed.headers).length
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
iterations: 300,
|
|
34
|
+
warmup: 30,
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "rust:http_parse_pipeline",
|
|
38
|
+
run: () => {
|
|
39
|
+
const parsed = readHttpPacked(rust.httpParseRequestPacked(f.httpRaw));
|
|
40
|
+
return (
|
|
41
|
+
parsed.method.length +
|
|
42
|
+
parsed.path.length +
|
|
43
|
+
Object.keys(parsed.headers).length
|
|
44
|
+
);
|
|
45
|
+
},
|
|
46
|
+
iterations: 300,
|
|
47
|
+
warmup: 30,
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { BenchFixtures, ComplexFixtures } from "../fixtures";
|
|
2
|
+
import type { BenchTask, ConcurrentBenchTask, StressBenchTask } from "../types";
|
|
3
|
+
import { cookieTasks } from "./cookie";
|
|
4
|
+
import { concurrentTasks } from "./concurrent";
|
|
5
|
+
import { complexTasks } from "./complex";
|
|
6
|
+
import { hashingTasks } from "./hashing";
|
|
7
|
+
import { hmacTasks } from "./hmac";
|
|
8
|
+
import { httpTasks } from "./http";
|
|
9
|
+
import { jsonTasks } from "./json";
|
|
10
|
+
import { jsonPatchTasks } from "./json-patch";
|
|
11
|
+
import { mimeTasks } from "./mime";
|
|
12
|
+
import { queryTasks } from "./query";
|
|
13
|
+
import { stressTasks } from "./stress";
|
|
14
|
+
import { tokenTasks } from "./token";
|
|
15
|
+
import { urlTasks } from "./url";
|
|
16
|
+
import { validationTasks } from "./validation";
|
|
17
|
+
import { websocketTasks } from "./websocket";
|
|
18
|
+
|
|
19
|
+
export function createAllTasks(fixtures: BenchFixtures): BenchTask[] {
|
|
20
|
+
return [
|
|
21
|
+
...jsonTasks(fixtures),
|
|
22
|
+
...httpTasks(fixtures),
|
|
23
|
+
...queryTasks(fixtures),
|
|
24
|
+
...cookieTasks(fixtures),
|
|
25
|
+
...tokenTasks(),
|
|
26
|
+
...websocketTasks(fixtures),
|
|
27
|
+
...jsonPatchTasks(fixtures),
|
|
28
|
+
...hmacTasks(fixtures),
|
|
29
|
+
...validationTasks(fixtures),
|
|
30
|
+
...hashingTasks(fixtures),
|
|
31
|
+
...mimeTasks(fixtures),
|
|
32
|
+
...urlTasks(fixtures),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createComplexTasks(fixtures: ComplexFixtures): BenchTask[] {
|
|
37
|
+
return complexTasks(fixtures);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function createConcurrentTasks(
|
|
41
|
+
fixtures: BenchFixtures,
|
|
42
|
+
complex: ComplexFixtures,
|
|
43
|
+
): ConcurrentBenchTask[] {
|
|
44
|
+
return concurrentTasks(fixtures, complex);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createStressTasks(
|
|
48
|
+
fixtures: BenchFixtures,
|
|
49
|
+
complex: ComplexFixtures,
|
|
50
|
+
): StressBenchTask[] {
|
|
51
|
+
return stressTasks(fixtures, complex);
|
|
52
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import type { BenchFixtures } from "../fixtures";
|
|
4
|
+
import type { BenchTask } from "../types";
|
|
5
|
+
|
|
6
|
+
export function jsonPatchTasks(f: BenchFixtures): BenchTask[] {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
name: "native:json_patch",
|
|
10
|
+
run: () => native.nativeJsonPatch(f.jsonDoc, f.jsonPatch).byteLength,
|
|
11
|
+
iterations: 500,
|
|
12
|
+
warmup: 50,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "rust:json_patch",
|
|
16
|
+
run: () => rust.jsonPatch(f.jsonDoc, f.jsonPatch).byteLength,
|
|
17
|
+
iterations: 500,
|
|
18
|
+
warmup: 50,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import type { BenchFixtures } from "../fixtures";
|
|
4
|
+
import type { BenchTask } from "../types";
|
|
5
|
+
|
|
6
|
+
export function jsonTasks(f: BenchFixtures): BenchTask[] {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
name: "native:json_valid",
|
|
10
|
+
run: () => native.nativeJsonValid(f.jsonPayload),
|
|
11
|
+
iterations: 100,
|
|
12
|
+
warmup: 10,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "rust:json_valid",
|
|
16
|
+
run: () => rust.jsonValid(f.jsonPayload),
|
|
17
|
+
iterations: 100,
|
|
18
|
+
warmup: 10,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "native:json_sum",
|
|
22
|
+
run: () => native.nativeJsonSum(f.jsonPayload),
|
|
23
|
+
iterations: 100,
|
|
24
|
+
warmup: 10,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "rust:json_sum",
|
|
28
|
+
run: () => rust.jsonSumIds(f.jsonPayload),
|
|
29
|
+
iterations: 100,
|
|
30
|
+
warmup: 10,
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import type { BenchFixtures } from "../fixtures";
|
|
4
|
+
import type { BenchTask } from "../types";
|
|
5
|
+
|
|
6
|
+
export function mimeTasks(f: BenchFixtures): BenchTask[] {
|
|
7
|
+
return [
|
|
8
|
+
{
|
|
9
|
+
name: "native:mime",
|
|
10
|
+
run: () => native.nativeMimeFromExtension("json").length,
|
|
11
|
+
iterations: 1000,
|
|
12
|
+
warmup: 100,
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: "rust:mime",
|
|
16
|
+
run: () => rust.mimeFromExtension(f.mimeExt).byteLength,
|
|
17
|
+
iterations: 1000,
|
|
18
|
+
warmup: 100,
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import { pairsToObject, readPairsPacked } from "../../shared/packed";
|
|
4
|
+
import type { BenchFixtures } from "../fixtures";
|
|
5
|
+
import type { BenchTask } from "../types";
|
|
6
|
+
|
|
7
|
+
export function queryTasks(f: BenchFixtures): BenchTask[] {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "native:query_parse",
|
|
11
|
+
run: () => native.nativeQueryParsePacked(f.queryStr).byteLength,
|
|
12
|
+
iterations: 500,
|
|
13
|
+
warmup: 50,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "rust:query_parse",
|
|
17
|
+
run: () => rust.queryParsePacked(f.queryStr).byteLength,
|
|
18
|
+
iterations: 500,
|
|
19
|
+
warmup: 50,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "native:query_parse_pipeline",
|
|
23
|
+
run: () => {
|
|
24
|
+
const obj = pairsToObject(
|
|
25
|
+
readPairsPacked(native.nativeQueryParsePacked(f.queryStr)),
|
|
26
|
+
);
|
|
27
|
+
return Object.keys(obj).length;
|
|
28
|
+
},
|
|
29
|
+
iterations: 300,
|
|
30
|
+
warmup: 30,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "rust:query_parse_pipeline",
|
|
34
|
+
run: () => {
|
|
35
|
+
const obj = pairsToObject(
|
|
36
|
+
readPairsPacked(rust.queryParsePacked(f.queryStr)),
|
|
37
|
+
);
|
|
38
|
+
return Object.keys(obj).length;
|
|
39
|
+
},
|
|
40
|
+
iterations: 300,
|
|
41
|
+
warmup: 30,
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import * as native from "../../baseline";
|
|
2
|
+
import { rust } from "../../rust-ffi";
|
|
3
|
+
import type { BenchFixtures, ComplexFixtures } from "../fixtures";
|
|
4
|
+
import type { StressBenchTask } from "../types";
|
|
5
|
+
|
|
6
|
+
export function stressTasks(
|
|
7
|
+
f: BenchFixtures,
|
|
8
|
+
_c: ComplexFixtures,
|
|
9
|
+
): StressBenchTask[] {
|
|
10
|
+
return [
|
|
11
|
+
// ── JSON validation stress ──
|
|
12
|
+
{
|
|
13
|
+
name: "native:json_valid_stress",
|
|
14
|
+
run: () => native.nativeJsonValid(f.jsonPayload),
|
|
15
|
+
durationMs: 2000,
|
|
16
|
+
warmupMs: 200,
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "rust:json_valid_stress",
|
|
20
|
+
run: () => rust.jsonValid(f.jsonPayload),
|
|
21
|
+
durationMs: 2000,
|
|
22
|
+
warmupMs: 200,
|
|
23
|
+
},
|
|
24
|
+
// ── JSON sum stress ──
|
|
25
|
+
{
|
|
26
|
+
name: "native:json_sum_stress",
|
|
27
|
+
run: () => native.nativeJsonSum(f.jsonPayload),
|
|
28
|
+
durationMs: 2000,
|
|
29
|
+
warmupMs: 200,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "rust:json_sum_stress",
|
|
33
|
+
run: () => rust.jsonSumIds(f.jsonPayload),
|
|
34
|
+
durationMs: 2000,
|
|
35
|
+
warmupMs: 200,
|
|
36
|
+
},
|
|
37
|
+
// ── HTTP parse stress ──
|
|
38
|
+
{
|
|
39
|
+
name: "native:http_parse_stress",
|
|
40
|
+
run: () => native.nativeHttpParseRequestPacked(f.httpRaw).byteLength,
|
|
41
|
+
durationMs: 2000,
|
|
42
|
+
warmupMs: 200,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "rust:http_parse_stress",
|
|
46
|
+
run: () => rust.httpParseRequestPacked(f.httpRaw).byteLength,
|
|
47
|
+
durationMs: 2000,
|
|
48
|
+
warmupMs: 200,
|
|
49
|
+
},
|
|
50
|
+
// ── HMAC stress ──
|
|
51
|
+
{
|
|
52
|
+
name: "native:hmac_sha256_stress",
|
|
53
|
+
run: () => native.nativeHmacSha256(f.hmacKey, f.hmacData).byteLength,
|
|
54
|
+
durationMs: 2000,
|
|
55
|
+
warmupMs: 200,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: "rust:hmac_sha256_stress",
|
|
59
|
+
run: () => rust.hmacSha256(f.hmacKey, f.hmacData).byteLength,
|
|
60
|
+
durationMs: 2000,
|
|
61
|
+
warmupMs: 200,
|
|
62
|
+
},
|
|
63
|
+
// ── CRC32 stress ──
|
|
64
|
+
{
|
|
65
|
+
name: "native:crc32_stress",
|
|
66
|
+
run: () => native.nativeCrc32(f.crcInput),
|
|
67
|
+
durationMs: 2000,
|
|
68
|
+
warmupMs: 200,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "rust:crc32_stress",
|
|
72
|
+
run: () => rust.crc32(f.crcInput),
|
|
73
|
+
durationMs: 2000,
|
|
74
|
+
warmupMs: 200,
|
|
75
|
+
},
|
|
76
|
+
// ── Query parse stress ──
|
|
77
|
+
{
|
|
78
|
+
name: "native:query_parse_stress",
|
|
79
|
+
run: () => native.nativeQueryParsePacked(f.queryStr).byteLength,
|
|
80
|
+
durationMs: 2000,
|
|
81
|
+
warmupMs: 200,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "rust:query_parse_stress",
|
|
85
|
+
run: () => rust.queryParsePacked(f.queryStr).byteLength,
|
|
86
|
+
durationMs: 2000,
|
|
87
|
+
warmupMs: 200,
|
|
88
|
+
},
|
|
89
|
+
// ── Email validation stress ──
|
|
90
|
+
{
|
|
91
|
+
name: "native:validate_email_stress",
|
|
92
|
+
run: () => (native.nativeValidateEmail(f.emailOk) ? 1 : 0),
|
|
93
|
+
durationMs: 2000,
|
|
94
|
+
warmupMs: 200,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "rust:validate_email_stress",
|
|
98
|
+
run: () => rust.validateEmail(f.emailOk),
|
|
99
|
+
durationMs: 2000,
|
|
100
|
+
warmupMs: 200,
|
|
101
|
+
},
|
|
102
|
+
// ── UUID validation stress ──
|
|
103
|
+
{
|
|
104
|
+
name: "native:validate_uuid_stress",
|
|
105
|
+
run: () => (native.nativeValidateUuid(f.uuidOk) ? 1 : 0),
|
|
106
|
+
durationMs: 2000,
|
|
107
|
+
warmupMs: 200,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "rust:validate_uuid_stress",
|
|
111
|
+
run: () => rust.validateUuid(f.uuidOk),
|
|
112
|
+
durationMs: 2000,
|
|
113
|
+
warmupMs: 200,
|
|
114
|
+
},
|
|
115
|
+
// ── Cookie parse stress ──
|
|
116
|
+
{
|
|
117
|
+
name: "native:cookie_parse_stress",
|
|
118
|
+
run: () => native.nativeCookieParsePacked(f.cookieStr).byteLength,
|
|
119
|
+
durationMs: 2000,
|
|
120
|
+
warmupMs: 200,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "rust:cookie_parse_stress",
|
|
124
|
+
run: () => rust.cookieParsePacked(f.cookieStr).byteLength,
|
|
125
|
+
durationMs: 2000,
|
|
126
|
+
warmupMs: 200,
|
|
127
|
+
},
|
|
128
|
+
// ── WebSocket accept stress ──
|
|
129
|
+
{
|
|
130
|
+
name: "native:ws_accept_key_stress",
|
|
131
|
+
run: () => native.nativeWsAcceptKey(f.wsKey).byteLength,
|
|
132
|
+
durationMs: 2000,
|
|
133
|
+
warmupMs: 200,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
name: "rust:ws_accept_key_stress",
|
|
137
|
+
run: () => rust.wsAcceptKey(f.wsKeyBytes).byteLength,
|
|
138
|
+
durationMs: 2000,
|
|
139
|
+
warmupMs: 200,
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
}
|