-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
110 lines (81 loc) · 4.09 KB
/
Copy pathmain.cpp
File metadata and controls
110 lines (81 loc) · 4.09 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include <stdexcept>
#include <chrono>
#include "engine/tick_store.hpp"
int main() {
try {
tick_store::Engine engine("ticks.bin");
engine.print_first_tick();
std::cout << "\nTotal ticks loaded: " << engine.get_num_ticks() << "\n\n";
constexpr std::int32_t target_symbol = 42;
{
constexpr std::int64_t start_time = 1'700'000'000'000;
constexpr std::int64_t end_time = 1'700'000'005'000;
std::cout << "=== Query 1 — Cold Start (Cache Miss + Sort) ===\n"
<< " Target symbol : " << target_symbol << "\n"
<< " Time window : [" << start_time << ", "
<< end_time << "]\n\n";
auto t0 = std::chrono::high_resolution_clock::now();
double avg = engine.smart_simd_query(target_symbol,
start_time,
end_time);
auto t1 = std::chrono::high_resolution_clock::now();
auto ms = std::chrono::duration_cast<
std::chrono::milliseconds>(t1 - t0).count();
auto us = std::chrono::duration_cast<
std::chrono::microseconds>(t1 - t0).count();
std::cout << " Average price : " << avg << "\n"
<< " Latency : " << ms << " ms ("
<< us << " µs)\n"
<< "==========================================\n\n";
}
{
constexpr std::int64_t start_time = 1'700'000'010'000;
constexpr std::int64_t end_time = 1'700'000'015'000;
std::cout << "=== Query 2 — Hot Cache (Skip Partition + Skip Sort) ===\n"
<< " Target symbol : " << target_symbol
<< " (same symbol)\n"
<< " Time window : [" << start_time << ", "
<< end_time << "]\n\n";
auto t0 = std::chrono::high_resolution_clock::now();
double avg = engine.smart_simd_query(target_symbol,
start_time,
end_time);
auto t1 = std::chrono::high_resolution_clock::now();
auto ms = std::chrono::duration_cast<
std::chrono::milliseconds>(t1 - t0).count();
auto us = std::chrono::duration_cast<
std::chrono::microseconds>(t1 - t0).count();
std::cout << " Average price : " << avg << "\n"
<< " Latency : " << ms << " ms ("
<< us << " µs)\n"
<< "==========================================\n\n";
}
{
constexpr std::int64_t start_time = 1'700'000'002'000;
constexpr std::int64_t end_time = 1'700'000'003'000;
std::cout << "=== Query 3 — O(log N) Payoff (Narrow Window) ===\n"
<< " Target symbol : " << target_symbol
<< " (same symbol, tiny window)\n"
<< " Time window : [" << start_time << ", "
<< end_time << "]\n\n";
auto t0 = std::chrono::high_resolution_clock::now();
double avg = engine.smart_simd_query(target_symbol,
start_time,
end_time);
auto t1 = std::chrono::high_resolution_clock::now();
auto ms = std::chrono::duration_cast<
std::chrono::milliseconds>(t1 - t0).count();
auto us = std::chrono::duration_cast<
std::chrono::microseconds>(t1 - t0).count();
std::cout << " Average price : " << avg << "\n"
<< " Latency : " << ms << " ms ("
<< us << " µs)\n"
<< "==========================================\n";
}
} catch (const std::runtime_error& e) {
std::cerr << "\n[FATAL ERROR] " << e.what() << "\n";
return 1;
}
return 0;
}