17
17
} ,
18
18
} ;
19
19
20
+ #[ derive( Clone , Copy , Debug ) ]
21
+ enum TestingStrategy {
22
+ Random ,
23
+ SimilarPrices ,
24
+ }
25
+
20
26
/// Benchmark the execution of the oracle program
21
- async fn run_benchmark ( num_publishers : usize ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
27
+ async fn run_benchmark (
28
+ num_publishers : usize ,
29
+ strategy : TestingStrategy ,
30
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
22
31
let mut sim = PythSimulator :: new ( ) . await ;
23
32
24
33
let mapping_keypair = sim. init_mapping ( ) . await ?;
@@ -40,14 +49,20 @@ async fn run_benchmark(num_publishers: usize) -> Result<(), Box<dyn std::error::
40
49
let mut rnd = rand:: rngs:: SmallRng :: seed_from_u64 ( 14 ) ;
41
50
42
51
for kp in publishers_keypairs. iter ( ) {
43
- // The ranges are chosen to create overlap between
44
- // publishers price set (price-conf, price, price + conf)
45
- let quote = Quote {
46
- price : rnd. gen_range ( 10000 ..11000 ) ,
47
- confidence : rnd. gen_range ( 1 ..1000 ) ,
48
- status : PC_STATUS_TRADING ,
52
+ let quote = match strategy {
53
+ TestingStrategy :: Random => Quote {
54
+ price : rnd. gen_range ( 10000 ..11000 ) ,
55
+ confidence : rnd. gen_range ( 1 ..1000 ) ,
56
+ status : PC_STATUS_TRADING ,
57
+ } ,
58
+ TestingStrategy :: SimilarPrices => Quote {
59
+ price : rnd. gen_range ( 10 ..12 ) ,
60
+ confidence : rnd. gen_range ( 1 ..3 ) ,
61
+ status : PC_STATUS_TRADING ,
62
+ } ,
49
63
} ;
50
64
65
+
51
66
sim. upd_price ( kp, price_pubkey, quote) . await ?;
52
67
}
53
68
@@ -67,21 +82,41 @@ async fn run_benchmark(num_publishers: usize) -> Result<(), Box<dyn std::error::
67
82
}
68
83
69
84
#[ tokio:: test]
70
- async fn test_benchmark_64_pubs ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
71
- run_benchmark ( 64 ) . await
85
+ async fn test_benchmark_64_pubs_random ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
86
+ run_benchmark ( 64 , TestingStrategy :: Random ) . await
87
+ }
88
+
89
+ #[ tokio:: test]
90
+ async fn test_benchmark_64_pubs_similar_prices ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
91
+ run_benchmark ( 64 , TestingStrategy :: SimilarPrices ) . await
92
+ }
93
+
94
+ #[ tokio:: test]
95
+ async fn test_benchmark_32_pubs_random ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
96
+ run_benchmark ( 32 , TestingStrategy :: Random ) . await
97
+ }
98
+
99
+ #[ tokio:: test]
100
+ async fn test_benchmark_32_pubs_similar_prices ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
101
+ run_benchmark ( 32 , TestingStrategy :: SimilarPrices ) . await
102
+ }
103
+
104
+ #[ tokio:: test]
105
+ async fn test_benchmark_16_pubs_random ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
106
+ run_benchmark ( 16 , TestingStrategy :: Random ) . await
72
107
}
73
108
74
109
#[ tokio:: test]
75
- async fn test_benchmark_32_pubs ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
76
- run_benchmark ( 32 ) . await
110
+ async fn test_benchmark_16_pubs_similar_prices ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
111
+ run_benchmark ( 16 , TestingStrategy :: SimilarPrices ) . await
77
112
}
78
113
79
114
#[ tokio:: test]
80
- async fn test_benchmark_16_pubs ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
81
- run_benchmark ( 16 ) . await
115
+ async fn test_benchmark_8_pubs_random ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
116
+ run_benchmark ( 8 , TestingStrategy :: Random ) . await
82
117
}
83
118
84
119
#[ tokio:: test]
85
- async fn test_benchmark_8_pubs ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
86
- run_benchmark ( 8 ) . await
120
+ async fn test_benchmark_8_pubs_similar_prices ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
121
+ run_benchmark ( 8 , TestingStrategy :: SimilarPrices ) . await
87
122
}
0 commit comments