-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerformanceBenchmark.cpp
More file actions
30 lines (23 loc) · 1004 Bytes
/
PerformanceBenchmark.cpp
File metadata and controls
30 lines (23 loc) · 1004 Bytes
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
#include <iostream>
#include <vector>
#include <chrono>
#include "OrderBook.h"
#include "Order.h"
void runBenchmark(OrderBook& orderBook, int numOrders = 1000) {
std::vector<Order> orders;
// Generate BUY and SELL orders alternately
for (int i = 0; i < numOrders; ++i) {
std::string id = "ORD" + std::to_string(i);
double price = 1.1000 + (i % 50) * 0.0001; // Vary price a bit
int quantity = 100 + (i % 10) * 10;
OrderType type = (i % 2 == 0) ? OrderType::BUY : OrderType::SELL;
orders.emplace_back(id, "EUR/USD", price, quantity, type);
}
auto start = std::chrono::high_resolution_clock::now();
for (const auto& order : orders) {
orderBook.addOrder(order);
}
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
std::cout << "Matched " << numOrders << " orders in " << duration.count() << " microseconds." << std::endl;
}