feat: ✨ interaction
fix: 🐛 checks
This commit is contained in:
parent
3cb31ff68b
commit
ec5c6008f2
1 changed files with 65 additions and 64 deletions
|
@ -16,83 +16,83 @@ 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) {
|
||||||
//b = true;
|
// b = true;
|
||||||
let square_root = (i as f64).sqrt() as u32;
|
let square_root = (i as f64).sqrt() as u32;
|
||||||
for j in (3..=square_root).step_by(2) {
|
for j in (3..=square_root).step_by(2) {
|
||||||
if i % j == 0 {
|
if i % j == 0 {
|
||||||
//println!("{} is even", i);
|
// println!("{} is even", i);
|
||||||
//b = false;
|
// b = false;
|
||||||
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) {
|
||||||
//b = true;
|
// b = true;
|
||||||
let square_root = (i as f64).sqrt() as u32;
|
let square_root = (i as f64).sqrt() as u32;
|
||||||
for j in (3..=square_root).step_by(2) {
|
for j in (3..=square_root).step_by(2) {
|
||||||
if i % j == 0 {
|
if i % j == 0 {
|
||||||
//println!("{} is even", i);
|
// println!("{} is even", i);
|
||||||
//b = false;
|
// b = false;
|
||||||
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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue