diff --git a/Cargo.lock b/Cargo.lock index 1e5b35d07..c3f1235df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,6 +260,7 @@ dependencies = [ "network_helpers", "num-bigint", "num-traits", + "rand 0.8.5", "roles_logic_sv2", "serde", "serde_json", diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 2470c83b5..297f0ef15 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -4,13 +4,13 @@ version = "0.1.0" edition = "2021" [dependencies] -async-std = "1.10.0" +async-std={version = "1.10.0", features = ["attributes"]} criterion = "0.5.1" # prometheus = "0.13.3" async-channel = "1.4.0" v1={path="../protocols/v1", package="sv1_api"} serde_json = "1.0.70" -iai="0.1.1" +iai="0.1" roles_logic_sv2 = { path = "../protocols/v2/roles-logic-sv2" } serde = { version = "1.0.89", default-features = false, features = ["derive", "alloc"] } num-bigint = "0.4.3" @@ -19,6 +19,7 @@ bitcoin="0.27.1" codec_sv2 = { path = "../protocols/v2/codec-sv2", features=["noise_sv2"] } binary_sv2 = { path = "../protocols/v2/binary-sv2/binary-sv2" } network_helpers = { path = "../utils/network-helpers", features=["async_std"] } +rand = "0.8.4" [[bench]] name = "criterion_sv1_benchmark" @@ -35,7 +36,7 @@ name = "criterion_sv2_benchmark" path = "benches/src/sv2/criterion_sv2_benchmark.rs" harness = false -[[bench]] -name = "iai_sv2_pool_benchmark" -path = "benches/src/sv2/iai_sv2_pool_benchmark.rs" -harness = false +# [[bench]] +# name = "iai_sv2_pool_benchmark" +# path = "benches/src/sv2/iai_sv2_pool_benchmark.rs" +# harness = false diff --git a/benches/benches/src/sv1/criterion_sv1_benchmark.rs b/benches/benches/src/sv1/criterion_sv1_benchmark.rs index ca76535b6..951927800 100644 --- a/benches/benches/src/sv1/criterion_sv1_benchmark.rs +++ b/benches/benches/src/sv1/criterion_sv1_benchmark.rs @@ -2,110 +2,129 @@ //! It measures connection time, send subscription latency and share submission time. use async_std::task; -use criterion::{Criterion, Throughput}; +use criterion::{Criterion, Throughput,black_box}; use std::env; use v1::ClientStatus; +use v1::IsClient; #[path = "./lib/client.rs"] mod client; use crate::client::*; -use async_std::sync::{Arc, Mutex}; +use async_std::sync::{Arc, Mutex,MutexGuard}; use std::time::Duration; -async fn client_connect() -> Arc>> { - let client = Client::new(0, "127.0.0.1:3002".parse().unwrap()).await; - task::sleep(Duration::from_millis(200)).await; - client -} -async fn send_configure_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - client.send_configure().await; - client.status = ClientStatus::Configured; -} +fn benchmark_get_subscribe(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-get-subscribe"); -async fn send_subscribe_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - client.send_subscribe().await; - return client.status = ClientStatus::Subscribed; + group.bench_function("client-sv1-get-subscribe", |b| { + b.iter(|| { + client.status = ClientStatus::Configured; + // TODO add bench also for Some(extranonce) + client.subscribe(black_box(10), None).unwrap(); + }); + }); } -async fn send_authorize_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - let username = env::var("WALLET_ADDRESS").unwrap_or("user".to_string()); - client - .send_authorize(username.to_string(), "12345".to_string()) - .await; +fn benchmark_subscribe_serialize(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-subscribe-serialize"); + + group.bench_function("client-sv1-subscribe-serialize", |b| { + b.iter(|| { + client.status = ClientStatus::Configured; + // TODO add bench also for Some(extranonce) + let mut subscribe = client.subscribe(black_box(10), None).unwrap(); + Client::serialize_message(black_box(subscribe)); + }); + }); } -async fn send_submit_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - let username = env::var("WALLET_ADDRESS").unwrap_or("user".to_string()); - client.send_submit(username.as_str()).await; + +fn benchmark_subscribe_serialize_deserialize(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-subscribe-serialize-deserialize"); + + group.bench_function("client-sv1-subscribe-serialize-deserialize", |b| { + b.iter(|| { + client.status = ClientStatus::Configured; + let mut subscribe = client.subscribe(black_box(10), None).unwrap(); + let mut serialized = Client::serialize_message(black_box(subscribe)); + Client::parse_message(black_box(serialized)); + }); + }); } -fn benchmark_connection_time(c: &mut Criterion) { - c.bench_function("connection_time", |b| { +fn benchmark_subscribe_serialize_deserialize_handle(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-subscribe-serialize-deserialize-handle"); + + group.bench_function("client-sv1-subscribe-serialize-deserialize-handle", |b| { b.iter(|| { - let client = task::block_on(client_connect()); - drop(client); + client.status = ClientStatus::Configured; + let mut subscribe = client.subscribe(black_box(10), None).unwrap(); + let mut serialized = Client::serialize_message(black_box(subscribe)); + let deserilized = Client::parse_message(black_box(serialized)); + client.handle_message(black_box(deserilized)); }); }); } -fn benchmark_configure(c: &mut Criterion) { - const SUBSCRIBE_MESSAGE_SIZE: u64 = 112; - let mut group = c.benchmark_group("sv1"); - group.throughput(Throughput::Bytes(SUBSCRIBE_MESSAGE_SIZE)); +fn benchmark_get_authorize(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-get-authorize"); - group.bench_function("configure", |b| { + group.bench_function("client-sv1-get-authorize", |b| { b.iter(|| { - let mut client = task::block_on(client_connect()); - task::block_on(send_configure_benchmark(&mut client)); - drop(client); + client.status = ClientStatus::Configured; + let authorize = client.authorize(black_box(10),black_box("user".to_string()),black_box("passowrd".to_string())).unwrap(); }); }); } -fn benchmark_subscribe(c: &mut Criterion) { - const SUBSCRIBE_MESSAGE_SIZE: u64 = 112; - let mut group = c.benchmark_group("sv1"); - group.throughput(Throughput::Bytes(SUBSCRIBE_MESSAGE_SIZE)); - group.bench_function("subscribe", |b| { +fn benchmark_authorize_serialize(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-authorize-serialize"); + + group.bench_function("client-sv1-authorize-serialize", |b| { b.iter(|| { - let mut client = task::block_on(client_connect()); - task::block_on(send_configure_benchmark(&mut client)); - task::block_on(send_subscribe_benchmark(&mut client)); - drop(client); + client.status = ClientStatus::Configured; + let authorize = client.authorize(black_box(10),black_box("user".to_string()),black_box("passowrd".to_string())).unwrap(); + let serialized = Client::serialize_message(black_box(authorize)); }); }); - group.finish(); } -async fn share_submit() { - let mut client = client_connect().await; - send_configure_benchmark(&mut client).await; - send_subscribe_benchmark(&mut client).await; - task::sleep(Duration::from_millis(1000)).await; - send_authorize_benchmark(&mut client).await; - send_submit_benchmark(&mut client).await +fn benchmark_authorize_serialize_deserialize(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-authorize-serialize-deserialize"); + + group.bench_function("client-sv1-authorize-serialize-deserialize", |b| { + b.iter(|| { + client.status = ClientStatus::Configured; + let authorize = client.authorize(black_box(10),black_box("user".to_string()),black_box("passowrd".to_string())).unwrap(); + let serialized = Client::serialize_message(black_box(authorize)); + Client::parse_message(black_box(serialized)); + }); + }); } -fn benchmark_share_submit(c: &mut Criterion) { - const SUBSCRIBE_MESSAGE_SIZE: u64 = 112; - let mut group = c.benchmark_group("sv1"); - group.throughput(Throughput::Bytes(SUBSCRIBE_MESSAGE_SIZE)); - group.bench_function("test_submit", |b| { +fn benchmark_authorize_serialize_deserialize_handle(c: &mut Criterion, mut client: Client) { + let mut group = c.benchmark_group("client-sv1-authorize-serialize-deserialize-handle"); + + group.bench_function("client-sv1-authorize-serialize-deserialize-handle", |b| { b.iter(|| { - task::block_on(share_submit()); - }) + client.status = ClientStatus::Configured; + let authorize = client.authorize(black_box(10),black_box("user".to_string()),black_box("passowrd".to_string())).unwrap(); + let serialized = Client::serialize_message(black_box(authorize)); + let deserilized = Client::parse_message(black_box(serialized)); + client.handle_message(black_box(deserilized)); + }); }); - group.finish(); } fn main() { - let mut criterion = Criterion::default().sample_size(50); - benchmark_connection_time(&mut criterion); - benchmark_configure(&mut criterion); - benchmark_subscribe(&mut criterion); - benchmark_share_submit(&mut criterion); + let mut criterion = Criterion::default().sample_size(50).measurement_time(std::time::Duration::from_secs(5)); + let client = Client::new(90); + benchmark_get_subscribe(&mut criterion, client.clone()); + benchmark_subscribe_serialize(&mut criterion, client.clone()); + benchmark_subscribe_serialize_deserialize(&mut criterion, client.clone()); + benchmark_subscribe_serialize_deserialize_handle(&mut criterion, client.clone()); + benchmark_get_authorize(&mut criterion, client.clone()); + benchmark_authorize_serialize(&mut criterion, client.clone()); + benchmark_authorize_serialize_deserialize(&mut criterion, client.clone()); + benchmark_authorize_serialize_deserialize_handle(&mut criterion, client.clone()); criterion.final_summary(); } diff --git a/benches/benches/src/sv1/iai_sv1_benchmark.rs b/benches/benches/src/sv1/iai_sv1_benchmark.rs index 478d405e6..e5c801dd9 100644 --- a/benches/benches/src/sv1/iai_sv1_benchmark.rs +++ b/benches/benches/src/sv1/iai_sv1_benchmark.rs @@ -1,62 +1,42 @@ //! The code uses iai library to measure the system requirements of sv1 client. -use async_std::{ - sync::{Arc, Mutex}, - task, -}; use iai::{black_box, main}; -use std::{env, time::Duration}; -use v1::ClientStatus; +use std::{env, time::Duration, boxed::Box}; +use v1::{ClientStatus,IsClient}; #[path = "./lib/client.rs"] mod client; use crate::client::Client; +use std::cell::UnsafeCell; -async fn client_connect() -> Arc>> { - let client = Client::new(0, "127.0.0.1:3002".parse().unwrap()).await; - task::sleep(Duration::from_millis(200)).await; - client -} -async fn send_configure_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - client.send_configure().await; +fn get_subscirbe() { + let mut client = Client::new(0); client.status = ClientStatus::Configured; + black_box(client.subscribe(black_box(10), None).unwrap()); } -async fn send_subscribe_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - client.send_subscribe().await; - return client.status = ClientStatus::Subscribed; -} - -async fn send_authorize_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - let username = env::var("WALLET_ADDRESS").unwrap_or("user".to_string()); - client - .send_authorize(username.to_string(), "12345".to_string()) - .await; -} -async fn send_submit_benchmark(client: &mut Arc>>) { - let mut client = client.lock().await; - let username = env::var("WALLET_ADDRESS").unwrap_or("user".to_string()); - client.send_submit(username.as_str()).await; -} - -async fn bench_submit() { - let mut client = client_connect().await; - send_configure_benchmark(&mut client).await; - send_subscribe_benchmark(&mut client).await; - task::sleep(Duration::from_millis(1000)).await; - send_authorize_benchmark(&mut client).await; - send_submit_benchmark(&mut client).await +fn serialize_subscirbe() { + let mut client = Client::new(0); + client.status = ClientStatus::Configured; + let mut subscribe = client.subscribe(black_box(10), None).unwrap(); + black_box(Client::serialize_message(black_box(subscribe))); } -fn benchmark_submit_share() { - task::block_on(bench_submit()); +fn serialize_deserialize_subscirbe() { + let mut client = Client::new(0); + client.status = ClientStatus::Configured; + let mut subscribe = client.subscribe(black_box(10), None).unwrap(); + let serlialized = Client::serialize_message(black_box(subscribe)); + Client::parse_message(black_box(serlialized)); } -fn iai_sv1_share_submit() { - black_box(benchmark_submit_share()); +fn serialize_deserialize_handle_subscirbe() { + let mut client = Client::new(0); + client.status = ClientStatus::Configured; + let mut subscribe = client.subscribe(black_box(10), None).unwrap(); + let serlialized = Client::serialize_message(black_box(subscribe)); + let serialized = Client::parse_message(black_box(serlialized)); + client.handle_message(black_box(serialized)); } -main!(iai_sv1_share_submit); +main!(get_subscirbe,serialize_subscirbe,serialize_deserialize_subscirbe,serialize_deserialize_handle_subscirbe); diff --git a/benches/benches/src/sv1/lib/client.rs b/benches/benches/src/sv1/lib/client.rs index 69981067e..0a2662e89 100644 --- a/benches/benches/src/sv1/lib/client.rs +++ b/benches/benches/src/sv1/lib/client.rs @@ -24,75 +24,21 @@ use v1::{ ClientStatus, IsClient, }; -pub struct Client<'a> { +#[derive(Debug,Clone)] +pub struct Client { client_id: u32, - extranonce1: Extranonce<'a>, + extranonce1: Extranonce<'static>, extranonce2_size: usize, version_rolling_mask: Option, version_rolling_min_bit: Option, pub status: ClientStatus, - last_notify: Option>, + last_notify: Option>, sented_authorize_request: Vec<(u64, String)>, // (id, user_name) authorized: Vec, - receiver_incoming: Receiver, - sender_outgoing: Sender, } -impl<'a> Client<'static> { - pub async fn new(client_id: u32, socket: SocketAddr) -> Arc>> { - let stream = loop { - // task::sleep(Duration::from_secs(1)).await; - let start_time = Instant::now(); - match TcpStream::connect(socket).await { - Ok(st) => { - println!( - "Connection time: {} micro secs", - start_time.elapsed().as_micros() - ); - println!("CLIENT - connected to server at {}", socket); - - break st; - } - Err(e) => { - println!("Server not ready... {}", e); - continue; - } - } - }; - - let arc_stream = Arc::new(stream); - - let (reader, writer) = (arc_stream.clone(), arc_stream); - - let (sender_incoming, receiver_incoming) = bounded(10); - let (sender_outgoing, receiver_outgoing): (Sender, Receiver) = bounded(10); - let reader_clone = reader.clone(); - task::spawn(async move { - let mut messages = BufReader::new(&*reader_clone).lines(); - while let Some(message) = messages.next().await { - match message { - Ok(message) => { - if let Err(send_error) = sender_incoming.send(message).await { - eprintln!("Error sending message: {}", send_error); - // Handle the error gracefully, e.g., logging, retrying, etc. - } - } - Err(read_error) => { - eprintln!("Error reading message: {}", read_error); - // Handle the error gracefully, e.g., logging, retrying, etc. - } - } - } - }); - - task::spawn(async move { - while let Ok(message) = receiver_outgoing.recv().await { - if let Err(e) = (&*writer).write_all(message.as_bytes()).await { - eprintln!("An error occured: {}", e); - continue; - } - } - }); +impl Client { + pub fn new(client_id: u32) -> Client { let client = Client { client_id, @@ -104,141 +50,56 @@ impl<'a> Client<'static> { last_notify: None, sented_authorize_request: vec![], authorized: vec![], - receiver_incoming, - sender_outgoing, }; - let client = Arc::new(Mutex::new(client)); - - let cloned = client.clone(); - - task::spawn(async move { - loop { - if let Some(mut self_) = cloned.try_lock() { - let incoming = self_.receiver_incoming.try_recv(); - self_.parse_message(incoming).await; - } - //It's healthy to sleep after giving up the lock so the other thread has a shot - //at acquiring it - it also prevents pegging the cpu - task::sleep(Duration::from_millis(100)).await; - } - }); - client } - async fn parse_message( - &mut self, - incoming_message: Result, - ) { - if let Ok(line) = incoming_message { - println!("CLIENT {} - message: {}", self.client_id, line); - match serde_json::from_str::(&line) { - Ok(message) => { - if let Err(err) = self.handle_message(message) { - eprintln!("{:?}", err); - } - } - Err(err) => { - eprintln!("Error while deserializing JSON-RPC message: {}", err) - } + // this is what we want to benchmark + pub fn parse_message( + incoming_message: String, + ) -> json_rpc::Message { + match serde_json::from_str::(&incoming_message) { + Ok(message) => message, + // no need to handle errors in benchmarks + Err(err) => panic!(), } - } } - async fn send_message(sender_outgoing: &Sender, msg: json_rpc::Message) { + // also this is what we want to benchmark + pub fn serialize_message(msg: json_rpc::Message) -> String { let json_msg = serde_json::to_string(&msg); match json_msg { - Ok(json_str) => { - let msg = format!("{}\n", json_str); - if let Err(err) = sender_outgoing.send(msg).await { - eprintln!("Error sending JSON-RPC message: {:?}", err); - } - } - Err(err) => { - eprintln!("Error serializing JSON-RPC message: {:?}", err); - } - } - } - - pub async fn send_subscribe(&mut self) { - loop { - if let ClientStatus::Configured = self.status { - break; - } + Ok(json_str) => json_str, + // no need to handle errors in benchmarks + Err(err) => panic!(), } - let id = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - let subscribe = self.subscribe(id, None).unwrap(); - Self::send_message(&self.sender_outgoing, subscribe).await; } - pub async fn send_authorize(&mut self, username: String, password: String) { - let id = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - if let Ok(authorize) = self.authorize(id, username, password) { - Self::send_message(&self.sender_outgoing, authorize).await; - } - } - - pub async fn send_submit(&mut self, username: &str) { - let id = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - let extranonce2 = extranonce_from_hex("00"); - let nonce = 78; - let version_bits = None; - self.authorize_user_name(username.to_string()); - let submit = self - .submit( - id, - username.to_string(), - extranonce2, - nonce, - nonce, - version_bits, - ) - .unwrap(); - Self::send_message(&self.sender_outgoing, submit).await; - } - - pub async fn send_configure(&mut self) { - let id = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - let configure = self.configure(id); - Self::send_message(&self.sender_outgoing, configure).await; - } } -impl<'a> IsClient<'a> for Client<'a> { +impl IsClient<'static> for Client { fn handle_set_difficulty( &mut self, _conf: &mut server_to_client::SetDifficulty, - ) -> Result<(), Error<'a>> { + ) -> Result<(), Error<'static>> { Ok(()) } fn handle_set_version_mask( &mut self, _conf: &mut server_to_client::SetVersionMask, - ) -> Result<(), Error<'a>> { + ) -> Result<(), Error<'static>> { Ok(()) } fn handle_set_extranonce( &mut self, _conf: &mut server_to_client::SetExtranonce, - ) -> Result<(), Error<'a>> { + ) -> Result<(), Error<'static>> { Ok(()) } - fn handle_notify(&mut self, notify: server_to_client::Notify<'a>) -> Result<(), Error<'a>> { + fn handle_notify(&mut self, notify: server_to_client::Notify<'static>) -> Result<(), Error<'static>> { self.last_notify = Some(notify); Ok(()) } @@ -246,22 +107,22 @@ impl<'a> IsClient<'a> for Client<'a> { fn handle_configure( &mut self, _conf: &mut server_to_client::Configure, - ) -> Result<(), Error<'a>> { + ) -> Result<(), Error<'static>> { Ok(()) } fn handle_subscribe( &mut self, - _subscribe: &server_to_client::Subscribe<'a>, - ) -> Result<(), Error<'a>> { + _subscribe: &server_to_client::Subscribe<'static>, + ) -> Result<(), Error<'static>> { Ok(()) } - fn set_extranonce1(&mut self, extranonce1: Extranonce<'a>) { + fn set_extranonce1(&mut self, extranonce1: Extranonce<'static>) { self.extranonce1 = extranonce1; } - fn extranonce1(&self) -> Extranonce<'a> { + fn extranonce1(&self) -> Extranonce<'static> { self.extranonce1.clone() } @@ -347,12 +208,11 @@ impl<'a> IsClient<'a> for Client<'a> { fn handle_error_message( &mut self, message: v1::Message, - ) -> Result, Error<'a>> { - println!("{:?}", message); + ) -> Result, Error<'static>> { Ok(None) } } -fn extranonce_from_hex<'a>(hex: &str) -> Extranonce<'a> { +fn extranonce_from_hex(hex: &str) -> Extranonce<'static> { let data = utils::decode_hex(hex).unwrap(); Extranonce::try_from(data).expect("Failed to convert hex to U256") } diff --git a/benches/benches/src/sv2/criterion_sv2_benchmark.rs b/benches/benches/src/sv2/criterion_sv2_benchmark.rs index 70f74fe30..85d0adfff 100644 --- a/benches/benches/src/sv2/criterion_sv2_benchmark.rs +++ b/benches/benches/src/sv2/criterion_sv2_benchmark.rs @@ -1,80 +1,81 @@ -use async_channel::{Receiver, Sender}; -use codec_sv2::{StandardEitherFrame, StandardSv2Frame}; -use criterion::{Criterion, Throughput}; -use roles_logic_sv2::parsers::MiningDeviceMessages; - -use async_std::net::TcpStream; -use codec_sv2::{HandshakeRole, Initiator}; - -use network_helpers::Connection; - -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -#[path = "./lib/client.rs"] -mod client; -use crate::client::Device; - -pub type Message = MiningDeviceMessages<'static>; -pub type StdFrame = StandardSv2Frame; -pub type EitherFrame = StandardEitherFrame; - -pub const AUTHORITY_PUBLIC_K: [u8; 32] = [ - 215, 11, 47, 78, 34, 232, 25, 192, 195, 168, 170, 209, 95, 181, 40, 114, 154, 226, 176, 190, - 90, 169, 238, 89, 191, 183, 97, 63, 194, 119, 11, 31, -]; - -fn benchmark_connection_time(c: &mut Criterion) { - c.bench_function("handle_connection", |b| { - b.iter(|| { - async_std::task::block_on(async { - let addr: SocketAddr = - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 34254); - let stream = TcpStream::connect(addr).await.unwrap(); - let (receiver, sender): (Receiver, Sender) = - Connection::new( - stream, - HandshakeRole::Initiator( - Initiator::from_raw_k(AUTHORITY_PUBLIC_K).unwrap(), - ), - 10, - ) - .await; - Device::connect(addr, receiver.clone(), sender.clone()).await - }); - }); - }); -} - -fn benchmark_share_submission(c: &mut Criterion) { - const SUBSCRIBE_MESSAGE_SIZE: u64 = 8; - let mut group = c.benchmark_group("sv2"); - group.throughput(Throughput::Bytes(SUBSCRIBE_MESSAGE_SIZE)); - - group.bench_function("share_submission", |b| { - b.iter(|| { - async_std::task::block_on(async { - let addr: SocketAddr = - SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 34254); - let stream = TcpStream::connect(addr).await.unwrap(); - let (receiver, sender): (Receiver, Sender) = - Connection::new( - stream, - HandshakeRole::Initiator( - Initiator::from_raw_k(AUTHORITY_PUBLIC_K).unwrap(), - ), - 10, - ) - .await; - - let handicap: u32 = 10; - Device::share_submission(addr, receiver.clone(), sender.clone(), handicap).await - }); - }); - }); -} - -fn main() { - let mut criterion = Criterion::default().sample_size(50); - benchmark_connection_time(&mut criterion); - benchmark_share_submission(&mut criterion); - criterion.final_summary(); -} +// use async_channel::{Receiver, Sender}; +// use codec_sv2::{StandardEitherFrame, StandardSv2Frame}; +// use criterion::{Criterion, Throughput}; +// use roles_logic_sv2::parsers::MiningDeviceMessages; +// +// use async_std::net::TcpStream; +// use codec_sv2::{HandshakeRole, Initiator}; +// +// use network_helpers::Connection; +// +// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +// #[path = "./lib/client.rs"] +// mod client; +// use crate::client::Device; +// +// pub type Message = MiningDeviceMessages<'static>; +// pub type StdFrame = StandardSv2Frame; +// pub type EitherFrame = StandardEitherFrame; +// +// pub const AUTHORITY_PUBLIC_K: [u8; 32] = [ +// 215, 11, 47, 78, 34, 232, 25, 192, 195, 168, 170, 209, 95, 181, 40, 114, 154, 226, 176, 190, +// 90, 169, 238, 89, 191, 183, 97, 63, 194, 119, 11, 31, +// ]; +// +// fn benchmark_connection_time(c: &mut Criterion) { +// c.bench_function("handle_connection", |b| { +// b.iter(|| { +// async_std::task::block_on(async { +// let addr: SocketAddr = +// SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 34254); +// let stream = TcpStream::connect(addr).await.unwrap(); +// let (receiver, sender): (Receiver, Sender) = +// Connection::new( +// stream, +// HandshakeRole::Initiator( +// Initiator::from_raw_k(AUTHORITY_PUBLIC_K).unwrap(), +// ), +// 10, +// ) +// .await; +// Device::connect(addr, receiver.clone(), sender.clone()).await +// }); +// }); +// }); +// } +// +// fn benchmark_share_submission(c: &mut Criterion) { +// const SUBSCRIBE_MESSAGE_SIZE: u64 = 8; +// let mut group = c.benchmark_group("sv2"); +// group.throughput(Throughput::Bytes(SUBSCRIBE_MESSAGE_SIZE)); +// +// group.bench_function("share_submission", |b| { +// b.iter(|| { +// async_std::task::block_on(async { +// let addr: SocketAddr = +// SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 34254); +// let stream = TcpStream::connect(addr).await.unwrap(); +// let (receiver, sender): (Receiver, Sender) = +// Connection::new( +// stream, +// HandshakeRole::Initiator( +// Initiator::from_raw_k(AUTHORITY_PUBLIC_K).unwrap(), +// ), +// 10, +// ) +// .await; +// +// let handicap: u32 = 10; +// Device::share_submission(addr, receiver.clone(), sender.clone(), handicap).await +// }); +// }); +// }); +// } +// +// fn main() { +// let mut criterion = Criterion::default().sample_size(50); +// benchmark_connection_time(&mut criterion); +// benchmark_share_submission(&mut criterion); +// criterion.final_summary(); +// } +fn main() {}