-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf_benchmarks.cpp
More file actions
69 lines (58 loc) · 1.99 KB
/
Copy pathperf_benchmarks.cpp
File metadata and controls
69 lines (58 loc) · 1.99 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
#include "UDPReceiver.hpp"
#include "benchmark.hpp"
#include "hft.hpp"
#include "utils/cpu_affinity.hpp"
#include <arpa/inet.h>
#include <cstring>
#include <iostream>
#include <vector>
using namespace NetFeed;
int main() {
// 0. Pin to CPU 1 and set real-time priority (SCHED_FIFO)
// Minimizes interrupts and context switches during the hot loop.
try {
pin_thread_to_cpu(8);
} catch (...) {
// Silent failure to avoid cout in performance mode
}
// 1. Initialize HFT symbol access for symbol index 1
std::vector<int64_t> precisions = {10, 10, 10, 10};
HFT::symbolAccessArray[1].init(precisions, 4, true, 1);
// Set storageTicks to exceed the benchmark iteration count to avoid disk I/O
// triggers
HFT::symbolAccessArray[1].storageTicks = 2000000000;
HFT::symbolAccessArray[1].symbol = 1;
// 2. Pre-generate a pool of 1 million packets to reuse
// Recycling the pool avoids allocating 1TB of memory while still exercising
// logic.
const size_t POOL_SIZE = 1000000;
std::vector<HFTStorage::Packet> packet_pool(POOL_SIZE);
for (size_t i = 0; i < POOL_SIZE; ++i) {
HFTStorage::Packet &pkt = packet_pool[i];
pkt.size = 72;
int64_t tick_be = htobe64(1);
int64_t data_be = htobe64(static_cast<int64_t>(i) + 100);
memcpy(pkt.data, &tick_be, 8);
for (int j = 1; j < 9; ++j) {
memcpy(pkt.data + j * 8, &data_be, 8);
}
}
// Warm-up phase
for (int i = 0; i < 1000000; ++i) {
process_packet(packet_pool[i % POOL_SIZE], 72);
}
// 3. Ultra-Scale Benchmark Loop (1 Billion Packets)
// No cout or logging inside this loop to preserve nanosecond precision.
const uint64_t iterations = 100000000;
Bench b("UDP_Perf_1B_Scale", "perf_1B_results.txt");
b.start(iterations);
for (uint64_t i = 0; i < iterations; ++i) {
const HFTStorage::Packet &pkt = packet_pool[i % POOL_SIZE];
b.tick();
process_packet(pkt, 72);
b.tock();
}
// Result is automatically saved to perf_1B_results.txt by Bench::end()
b.end();
return 0;
}