feat: interaction

fix: 🐛 checks
This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-05-28 03:14:27 +03:00
parent 3cb31ff68b
commit ec5c6008f2

View file

@ -16,29 +16,29 @@ fn get_input() -> u32 {
}; };
} }
} }
fn prime(start: u32, finish: u32) { fn prime(mut start: u32, finish: u32) {
// if start > finish { if start > finish {
// println!("None"); println!("None");
// return; return;
// } }
// if finish < 2 { if finish < 2 {
// println!("None"); println!("None");
// return; return;
// } }
// println!("\t2"); // println!("\t2");
// if finish == 2 { if finish == 2 {
// return; return;
// } }
// if start < 3 { if start < 3 {
// start = 3; start = 3;
// } }
// if start % 2 == 0 { if start % 2 == 0 {
// start += 1; start += 1;
// } }
// let mut b; // let mut b;
for i in (start..=finish).step_by(2) { for i in (start..=finish).step_by(2) {
@ -51,35 +51,35 @@ fn prime(start: u32, finish: u32) {
break; break;
} }
} }
// if b == true { // if b {
// println!("\t{}", i); // println!("\t{}", i);
// } // }
} }
} }
async fn prime_async(start: u32, finish: u32) { async fn prime_async(mut start: u32, finish: u32) {
// if start > finish { if start > finish {
// println!("None"); println!("None");
// return; return;
// } }
// if finish < 2 { if finish < 2 {
// println!("None"); println!("None");
// return; return;
// } }
// println!("\t2"); // println!("\t2");
// if finish == 2 { if finish == 2 {
// return; return;
// } }
// if start < 3 { if start < 3 {
// start = 3; start = 3;
// } }
// if start % 2 == 0 { if start % 2 == 0 {
// start += 1; start += 1;
// } }
// let mut b; // let mut b;
for i in (start..=finish).step_by(2) { for i in (start..=finish).step_by(2) {
@ -92,7 +92,7 @@ async fn prime_async(start: u32, finish: u32) {
break; break;
} }
} }
// if b == true { // if b {
// println!("\t{}", i); // println!("\t{}", i);
// } // }
} }
@ -101,20 +101,18 @@ async fn prime_async(start: u32, finish: u32) {
async fn main() { async fn main() {
println!("Hello, world!"); println!("Hello, world!");
// println!("Start Point for Prime = ↓"); println!("Start Point for Prime = ↓");
// let start = get_input(); let start = get_input();
// println!("End Point for Prime = ↓"); println!("End Point for Prime = ↓");
// let finish = get_input(); let finish = get_input();
println!("How Many Thread Do You Want = ↓"); println!("How Many Thread Do You Want at Max = ↓");
let thread_count = get_input(); let thread_count = get_input();
let start = 3;
let finish = 10000000;
let mut time_values_normal_thread = vec![]; let mut time_values_normal_thread = vec![];
let mut time_values_tokio_thread = vec![]; let mut time_values_tokio_thread = vec![];
let normal_thread_total_instant = Instant::now();
for i in 1..thread_count + 1 { for i in 1..thread_count + 1 {
let thread_count = i; let thread_count = i;
let mut threads = vec![]; let mut threads = vec![];
@ -131,7 +129,9 @@ async fn main() {
time_values_normal_thread.push(time_elapsed); time_values_normal_thread.push(time_elapsed);
println!("Elapsed: {:#?} with {} Normal Thread(s)", time_elapsed, i); println!("Elapsed: {:#?} with {} Normal Thread(s)", time_elapsed, i);
} }
let normal_thread_total_elapsed = normal_thread_total_instant.elapsed();
let tokio_thread_total_instant = Instant::now();
for i in 1..thread_count + 1 { for i in 1..thread_count + 1 {
let thread_count = i; let thread_count = i;
let mut threads = vec![]; let mut threads = vec![];
@ -148,30 +148,31 @@ async fn main() {
time_values_tokio_thread.push(time_elapsed); time_values_tokio_thread.push(time_elapsed);
println!("Elapsed: {:#?} with {} Tokio Thread(s)", time_elapsed, i); println!("Elapsed: {:#?} with {} Tokio Thread(s)", time_elapsed, i);
} }
let tokio_thread_total_elapsed = tokio_thread_total_instant.elapsed();
let mut normal_bench = (Duration::MAX, 0); let mut normal_bench = (Duration::MAX, 0);
for i in 0..time_values_normal_thread.len() { for (i, thread_time_elapsed) in time_values_normal_thread.iter().enumerate() {
if normal_bench.0 > time_values_normal_thread[i] { if normal_bench.0 > *thread_time_elapsed {
normal_bench.0 = time_values_normal_thread[i]; normal_bench.0 = *thread_time_elapsed;
normal_bench.1 = i + 1; normal_bench.1 = i + 1;
} }
} }
let mut tokio_bench = (Duration::MAX, 0); let mut tokio_bench = (Duration::MAX, 0);
for i in 0..time_values_tokio_thread.len() { for (i, thread_time_elapsed) in time_values_tokio_thread.iter().enumerate() {
if tokio_bench.0 > time_values_tokio_thread[i] { if tokio_bench.0 > *thread_time_elapsed {
tokio_bench.0 = time_values_tokio_thread[i]; tokio_bench.0 = *thread_time_elapsed;
tokio_bench.1 = i + 1; tokio_bench.1 = i + 1;
} }
} }
println!( println!(
"\n\nNormal Thread | Bench Results: Min time {:#?} with {} thread", "\n\nNormal Thread | Bench Results: Min time {:#?} with {} thread\n\tTotal Time Elapsed: {:#?}",
normal_bench.0, normal_bench.1 normal_bench.0, normal_bench.1, normal_thread_total_elapsed,
); );
println!( println!(
"\n\nTokio Thread | Bench Results: Min time {:#?} with {} thread", "\n\nTokio Thread | Bench Results: Min time {:#?} with {} thread\n\tTotal Time Elapsed: {:#?}",
tokio_bench.0, tokio_bench.1 tokio_bench.0, tokio_bench.1, tokio_thread_total_elapsed,
); );
} }