-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.d
More file actions
74 lines (65 loc) · 2.2 KB
/
evaluate.d
File metadata and controls
74 lines (65 loc) · 2.2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import std.stdio;
import std.file;
import std.datetime;
import std.string;
import std.json;
import std.conv;
import std.process;
import core.sys.windows.windows; // Windows API
import core.sys.windows.psapi; // ✅ Import PSAPI for process memory info
void main() {
// File path
string filePath = "5mb_json.json";
string json_string = readText(filePath);
// Parsing
writeln("--- jsoniopipe ---");
auto startMemory = getMemoryUsageKB();
auto start = Clock.currTime();
JSONValue json = parseJSON(json_string);
auto end = Clock.currTime();
auto duration = end - start;
writeln("Parsing time: ", duration.total!"msecs", " ms");
auto endMemory = getMemoryUsageKB();
writeln("Memory usage: ", endMemory - startMemory, " KB");
// Validation Speed
start = Clock.currTime();
bool isValid = isValidJson(json_string);
end = Clock.currTime();
duration = end - start;
writeln("Validation Time: ", duration.total!"msecs", " ms");
// Serialization
start = Clock.currTime();
string serialized_string = json.toString();
end = Clock.currTime();
duration = end - start;
writeln("Serialization time: ", duration.total!"msecs", " ms");
// DOM access
if (json.type == JSONType.object) {
start = Clock.currTime();
auto glossary = json["glossary"];
if (glossary.type == JSONType.object) {
auto title = glossary["title"];
if (title.type == JSONType.string) {
string str_title = title.str;
}
}
end = Clock.currTime();
duration = end - start;
writeln("DOM access time: ", duration.total!"usecs", " microseconds");
}
}
// ✅ Fixed: Windows-compatible memory usage function
long getMemoryUsageKB() {
PROCESS_MEMORY_COUNTERS memInfo;
if (GetProcessMemoryInfo(GetCurrentProcess(), &memInfo, cast(UINT)memInfo.sizeof))
return cast(long) (memInfo.WorkingSetSize / 1024);
return 0;
}
bool isValidJson(string json_string) {
try {
JSONValue json = parseJSON(json_string);
return true;
} catch (Exception e) {
return false;
}
}