feat: ✨ interaction
fix: 🐛 checks
This commit is contained in:
parent
3cb31ff68b
commit
ec5c6008f2
1 changed files with 65 additions and 64 deletions
|
@ -16,29 +16,29 @@ fn get_input() -> u32 {
|
|||
};
|
||||
}
|
||||
}
|
||||
fn prime(start: u32, finish: u32) {
|
||||
// if start > finish {
|
||||
// println!("None");
|
||||
// return;
|
||||
// }
|
||||
fn prime(mut start: u32, finish: u32) {
|
||||
if start > finish {
|
||||
println!("None");
|
||||
return;
|
||||
}
|
||||
|
||||
// if finish < 2 {
|
||||
// println!("None");
|
||||
// return;
|
||||
// }
|
||||
if finish < 2 {
|
||||
println!("None");
|
||||
return;
|
||||
}
|
||||
|
||||
// println!("\t2");
|
||||
// if finish == 2 {
|
||||
// return;
|
||||
// }
|
||||
if finish == 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
// if start < 3 {
|
||||
// start = 3;
|
||||
// }
|
||||
if start < 3 {
|
||||
start = 3;
|
||||
}
|
||||
|
||||
// if start % 2 == 0 {
|
||||
// start += 1;
|
||||
// }
|
||||
if start % 2 == 0 {
|
||||
start += 1;
|
||||
}
|
||||
// let mut b;
|
||||
|
||||
for i in (start..=finish).step_by(2) {
|
||||
|
@ -51,35 +51,35 @@ fn prime(start: u32, finish: u32) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// if b == true {
|
||||
// if b {
|
||||
// println!("\t{}", i);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
async fn prime_async(start: u32, finish: u32) {
|
||||
// if start > finish {
|
||||
// println!("None");
|
||||
// return;
|
||||
// }
|
||||
async fn prime_async(mut start: u32, finish: u32) {
|
||||
if start > finish {
|
||||
println!("None");
|
||||
return;
|
||||
}
|
||||
|
||||
// if finish < 2 {
|
||||
// println!("None");
|
||||
// return;
|
||||
// }
|
||||
if finish < 2 {
|
||||
println!("None");
|
||||
return;
|
||||
}
|
||||
|
||||
// println!("\t2");
|
||||
// if finish == 2 {
|
||||
// return;
|
||||
// }
|
||||
if finish == 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
// if start < 3 {
|
||||
// start = 3;
|
||||
// }
|
||||
if start < 3 {
|
||||
start = 3;
|
||||
}
|
||||
|
||||
// if start % 2 == 0 {
|
||||
// start += 1;
|
||||
// }
|
||||
if start % 2 == 0 {
|
||||
start += 1;
|
||||
}
|
||||
// let mut b;
|
||||
|
||||
for i in (start..=finish).step_by(2) {
|
||||
|
@ -92,7 +92,7 @@ async fn prime_async(start: u32, finish: u32) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// if b == true {
|
||||
// if b {
|
||||
// println!("\t{}", i);
|
||||
// }
|
||||
}
|
||||
|
@ -101,20 +101,18 @@ async fn prime_async(start: u32, finish: u32) {
|
|||
async fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
// println!("Start Point for Prime = ↓");
|
||||
// let start = get_input();
|
||||
println!("Start Point for Prime = ↓");
|
||||
let start = get_input();
|
||||
|
||||
// println!("End Point for Prime = ↓");
|
||||
// let finish = get_input();
|
||||
println!("End Point for Prime = ↓");
|
||||
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 start = 3;
|
||||
let finish = 10000000;
|
||||
|
||||
let mut time_values_normal_thread = vec![];
|
||||
let mut time_values_tokio_thread = vec![];
|
||||
let normal_thread_total_instant = Instant::now();
|
||||
for i in 1..thread_count + 1 {
|
||||
let thread_count = i;
|
||||
let mut threads = vec![];
|
||||
|
@ -131,7 +129,9 @@ async fn main() {
|
|||
time_values_normal_thread.push(time_elapsed);
|
||||
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 {
|
||||
let thread_count = i;
|
||||
let mut threads = vec![];
|
||||
|
@ -148,30 +148,31 @@ async fn main() {
|
|||
time_values_tokio_thread.push(time_elapsed);
|
||||
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);
|
||||
for i in 0..time_values_normal_thread.len() {
|
||||
if normal_bench.0 > time_values_normal_thread[i] {
|
||||
normal_bench.0 = time_values_normal_thread[i];
|
||||
for (i, thread_time_elapsed) in time_values_normal_thread.iter().enumerate() {
|
||||
if normal_bench.0 > *thread_time_elapsed {
|
||||
normal_bench.0 = *thread_time_elapsed;
|
||||
normal_bench.1 = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
let mut tokio_bench = (Duration::MAX, 0);
|
||||
for i in 0..time_values_tokio_thread.len() {
|
||||
if tokio_bench.0 > time_values_tokio_thread[i] {
|
||||
tokio_bench.0 = time_values_tokio_thread[i];
|
||||
for (i, thread_time_elapsed) in time_values_tokio_thread.iter().enumerate() {
|
||||
if tokio_bench.0 > *thread_time_elapsed {
|
||||
tokio_bench.0 = *thread_time_elapsed;
|
||||
tokio_bench.1 = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!(
|
||||
"\n\nNormal Thread | Bench Results: Min time {:#?} with {} thread",
|
||||
normal_bench.0, normal_bench.1
|
||||
"\n\nNormal Thread | Bench Results: Min time {:#?} with {} thread\n\tTotal Time Elapsed: {:#?}",
|
||||
normal_bench.0, normal_bench.1, normal_thread_total_elapsed,
|
||||
);
|
||||
|
||||
println!(
|
||||
"\n\nTokio Thread | Bench Results: Min time {:#?} with {} thread",
|
||||
tokio_bench.0, tokio_bench.1
|
||||
"\n\nTokio Thread | Bench Results: Min time {:#?} with {} thread\n\tTotal Time Elapsed: {:#?}",
|
||||
tokio_bench.0, tokio_bench.1, tokio_thread_total_elapsed,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue