-
Notifications
You must be signed in to change notification settings - Fork 88
/
uniswap.rs
75 lines (67 loc) · 2.19 KB
/
uniswap.rs
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
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use ethers::prelude::*;
use subway_rs::uniswap::*;
use tokio::runtime;
fn bench_univ2_router_address(c: &mut Criterion) {
c.bench_function("uniswap v2 router", |b| {
b.iter(|| get_univ2_router_address())
});
}
fn bench_univ2_factory_address(c: &mut Criterion) {
c.bench_function("uniswap v2 factory", |b| {
b.iter(|| get_univ2_factory_address())
});
}
fn bench_calculate_uniswap_v2_pair_address(c: &mut Criterion) {
let addr_a = Address::random();
let addr_b = Address::random();
c.bench_function("calculate uniswap v2 pair addresses", |b| {
b.iter(|| calculate_uniswap_v2_pair_address(&addr_a, &addr_b))
});
}
fn bench_get_uniswap_v2_pair_address(c: &mut Criterion) {
let addr_a = Address::random();
let addr_b = Address::random();
c.bench_function("uniswap v2 factory", |b| {
let rt = runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
b.to_async(rt)
.iter(|| get_uniswap_v2_pair_address(&addr_a, &addr_b))
});
}
fn bench_pair_addresses(c: &mut Criterion) {
let mut group = c.benchmark_group("UniswapPairAddressRetrievers");
let addr_a = Address::random();
let addr_b = Address::random();
let i = 1u64;
group.bench_with_input(
BenchmarkId::new("Calculated", &i),
&(&addr_a, &addr_b),
|b, (aa, ab)| b.iter(|| calculate_uniswap_v2_pair_address(aa, ab)),
);
group.bench_with_input(
BenchmarkId::new("Fetched", i),
&(&addr_a, &addr_b),
|b, (aa, ab)| {
let rt = runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
b.to_async(rt).iter(|| get_uniswap_v2_pair_address(aa, ab));
},
);
group.finish();
}
criterion_group! {
name = uniswap_benches;
config = Criterion::default();
targets =
bench_univ2_router_address,
bench_univ2_factory_address,
bench_calculate_uniswap_v2_pair_address,
bench_get_uniswap_v2_pair_address,
bench_pair_addresses
}
criterion_main!(uniswap_benches);