Repository navigation
Expand file tree
/
Copy pathengine_bench.rs
More file actions
97 lines (93 loc) · 2.51 KB
/
Copy pathengine_bench.rs
File metadata and controls
97 lines (93 loc) · 2.51 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
use apex_match::orderbook::OrderBook;
use apex_match::types::{Order, OrderType, STPMode, Side, TimeInForce};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn bench_order_insertion(c: &mut Criterion) {
c.bench_function("orderbook_limit_insert", |b| {
let mut book = OrderBook::new(1);
let mut id = 1u64;
b.iter(|| {
let order = Order::new(
black_box(id),
100,
1,
Side::Buy,
OrderType::Limit,
TimeInForce::GTC,
STPMode::None,
10_000,
10,
1000,
);
id += 1;
let _ = book.match_order(order);
});
});
}
fn bench_order_crossing_match(c: &mut Criterion) {
c.bench_function("orderbook_match_fill", |b| {
let mut book = OrderBook::new(1);
// Pre-fill asks
for i in 1..=10_000 {
let ask = Order::new(
i,
100,
1,
Side::Sell,
OrderType::Limit,
TimeInForce::GTC,
STPMode::None,
10_000,
10,
1000,
);
let _ = book.match_order(ask);
}
let mut id = 20_000u64;
b.iter(|| {
let buy = Order::new(
black_box(id),
200,
1,
Side::Buy,
OrderType::Limit,
TimeInForce::IOC,
STPMode::None,
10_000,
10,
1000,
);
id += 1;
let _ = book.match_order(buy);
});
});
}
fn bench_order_cancellation(c: &mut Criterion) {
c.bench_function("orderbook_cancel_order", |b| {
let mut book = OrderBook::new(1);
let mut id = 1u64;
b.iter(|| {
let order = Order::new(
id,
100,
1,
Side::Buy,
OrderType::Limit,
TimeInForce::GTC,
STPMode::None,
10_000,
10,
1000,
);
let _ = book.match_order(order);
let _ = book.cancel_order(black_box(id), 2000);
id += 1;
});
});
}
criterion_group!(
benches,
bench_order_insertion,
bench_order_crossing_match,
bench_order_cancellation
);
criterion_main!(benches);