forked from stratum-mining/stratum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Fi3/ExampleBenches
Example sv1
- Loading branch information
Showing
6 changed files
with
232 additions
and
370 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Mutex<Client<'static>>> { | ||
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<Mutex<Client<'static>>>) { | ||
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<Mutex<Client<'static>>>) { | ||
let mut client = client.lock().await; | ||
client.send_subscribe().await; | ||
return client.status = ClientStatus::Subscribed; | ||
} | ||
|
||
async fn send_authorize_benchmark(client: &mut Arc<Mutex<Client<'static>>>) { | ||
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<Mutex<Client<'static>>>) { | ||
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); |
Oops, something went wrong.