-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_data_new.cpp
More file actions
42 lines (34 loc) · 1.21 KB
/
generate_data_new.cpp
File metadata and controls
42 lines (34 loc) · 1.21 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <random>
int main() {
std::string filename = "huge.json";
size_t target_size = 256 * 1024 * 1024; // 256MB
std::ofstream f(filename, std::ios::binary);
f << "[";
std::string entry_template = R"({"id":123456,"name":"Item 123456","active":true,"scores":[1,2,3,4,5],"description":"This is a test object to fill up memory and test throughput."})";
size_t current_size = 1; // '['
bool first = true;
while (current_size < target_size - 100) {
if (!first) {
f << ",";
current_size++;
}
f << entry_template;
current_size += entry_template.size();
first = false;
}
f << "]";
f.close();
std::cout << "Generated huge.json (" << current_size << " bytes)" << std::endl;
// Unaligned test
std::ofstream f_un( "unaligned.json", std::ios::binary);
// Pad with bytes to make it unaligned relative to 64-byte boundary if loaded at 0
// But typically we simulate unalignment in the loader.
// Here we just write valid JSON. We will offset the pointer in the test.
f_un << R"({"test": "unaligned"})";
f_un.close();
return 0;
}