-
Notifications
You must be signed in to change notification settings - Fork 329
Expand file tree
/
Copy pathstring_heavy.rhai
More file actions
26 lines (24 loc) · 945 Bytes
/
string_heavy.rhai
File metadata and controls
26 lines (24 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// String-heavy Rhai script for benchmarking string interning performance.
//
// This script is intentionally designed to exercise the Rhai string interner
// frequently: each iteration of the loop performs string concatenation and map
// key lookups, both of which acquire the RwLock on the StringsInterner when
// the `sync` feature is enabled.
//
// The goal is to produce a measurable difference between default interning
// (256 strings, RwLock acquired per op) and disabled interning (0, no lock).
fn supergraph_service(service) {
let request_callback = Fn("process_request");
service.map_request(request_callback);
}
fn process_request(request) {
let prefix = "x-rhai-bench-";
let i = 0;
while i < 20 {
let key = prefix + to_string(i);
let val = "bench-value-" + to_string(i) + "-done";
request.headers[key] = val;
i += 1;
}
request.context["rhai_bench_complete"] = "true";
}