1717 } ,
1818} ;
1919
20+ #[ derive( Clone , Copy , Debug ) ]
21+ enum TestingStrategy {
22+ Random ,
23+ SimilarPrices ,
24+ }
25+
2026/// 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 > > {
2231 let mut sim = PythSimulator :: new ( ) . await ;
2332
2433 let mapping_keypair = sim. init_mapping ( ) . await ?;
@@ -40,14 +49,20 @@ async fn run_benchmark(num_publishers: usize) -> Result<(), Box<dyn std::error::
4049 let mut rnd = rand:: rngs:: SmallRng :: seed_from_u64 ( 14 ) ;
4150
4251 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+ } ,
4963 } ;
5064
65+
5166 sim. upd_price ( kp, price_pubkey, quote) . await ?;
5267 }
5368
@@ -67,21 +82,41 @@ async fn run_benchmark(num_publishers: usize) -> Result<(), Box<dyn std::error::
6782}
6883
6984#[ 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
72107}
73108
74109#[ 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
77112}
78113
79114#[ 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
82117}
83118
84119#[ 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
87122}
0 commit comments