MCPcopy Create free account
hub / github.com/DmitriBogdanov/UTL / generate_test_data

Function generate_test_data

benchmarks/module_json/parse_serialize.cpp:27–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25// ======================
26
27void generate_test_data() {
28 // Generate string JSON data
29 std::vector<std::string> strings(120'000);
30
31 for (auto& str : strings) {
32
33 // Create string of random letters
34 str = std::string(random::uniform(0, 120), '0');
35 for (auto& ch : str) ch = random::uniform('a', 'z');
36
37 // Add some escapes at random
38 if (!str.empty() && random::uniform_double() < 0.1) {
39 const auto max_pos = static_cast<random::Uint>(str.size() - 1);
40 str.at(random::uniform_uint(0, max_pos)) =
41 random::choose({'"', '\\', '/', '\b', '\f', '\n', '\r', '\t'});
42 }
43 }
44
45 json::Node(strings).to_file("benchmarks/data/strings.json");
46
47 // Generate numeric JSON data
48 std::vector<double> numbers(180'000);
49
50 for (auto& num : numbers) num = random::choose({random::uniform(-10., 10.), random::uniform(-1e108, 1e108)});
51
52 json::Node(numbers).to_file("benchmarks/data/numbers.json");
53}
54
55// =================
56// --- Benchmark ---

Callers

nothing calls this directly

Calls 8

uniformFunction · 0.50
uniform_doubleFunction · 0.50
uniform_uintFunction · 0.50
chooseFunction · 0.50
NodeClass · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
to_fileMethod · 0.45

Tested by

no test coverage detected