-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigVSSmallobject.cpp
More file actions
58 lines (50 loc) · 1.29 KB
/
BigVSSmallobject.cpp
File metadata and controls
58 lines (50 loc) · 1.29 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
#include <benchmark/benchmark.h>
#include <vector>
#include <string>
#include <memory>
#include <cstdlib>
struct SmallOrder {
int price;
int quantity;
};
struct BigOrder {
long long order_id;
int price;
int quantity;
std::string broker;
std::string notes;
std::string trader_name;
std::string exchange;
};
struct OrderMeta {
std::string broker;
std::string notes;
std::string trader_name;
std::string exchange;
};
struct Order {
long long order_id;
int price;
int quantity;
std::unique_ptr<OrderMeta> meta;
};
template <typename T>
static void BM_SumQuantity(benchmark::State& state) {
const size_t N = state.range(0);
std::vector<T> orders(N);
for (auto& o : orders) {
o.price = std::rand() % 1000;
o.quantity = std::rand() % 100;
}
for (auto _ : state) {
int sum = 0;
for (const auto& o : orders) {
sum += o.quantity;
}
benchmark::DoNotOptimize(sum);
}
}
BENCHMARK_TEMPLATE(BM_SumQuantity, SmallOrder)->Arg(1'000'000)->Unit(benchmark::kMillisecond);;
BENCHMARK_TEMPLATE(BM_SumQuantity, BigOrder)->Arg(1'000'000)->Unit(benchmark::kMillisecond);;
BENCHMARK_TEMPLATE(BM_SumQuantity, Order)->Arg(1'000'000)->Unit(benchmark::kMillisecond);;
BENCHMARK_MAIN();