|
|
@ -1,11 +1,11 @@
|
|
|
|
|
|
|
|
use may::go;
|
|
|
|
|
|
|
|
use may::sync::mpmc::{channel, Sender};
|
|
|
|
use num_cpus;
|
|
|
|
use num_cpus;
|
|
|
|
use std::fs::{OpenOptions};
|
|
|
|
|
|
|
|
use std::io::prelude::*;
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::env;
|
|
|
|
use std::time::{Instant};
|
|
|
|
use std::fs::OpenOptions;
|
|
|
|
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io::BufWriter;
|
|
|
|
use std::io::BufWriter;
|
|
|
|
use may::sync::mpmc::{channel, Sender};
|
|
|
|
use std::time::Instant;
|
|
|
|
use may::go;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
|
may::config().set_workers(num_cpus::get());
|
|
|
|
may::config().set_workers(num_cpus::get());
|
|
|
@ -40,7 +40,10 @@ fn main() {
|
|
|
|
let prime = rx.recv().unwrap();
|
|
|
|
let prime = rx.recv().unwrap();
|
|
|
|
prime_count += 1;
|
|
|
|
prime_count += 1;
|
|
|
|
println!("\r{: <30}", prime);
|
|
|
|
println!("\r{: <30}", prime);
|
|
|
|
print!("{} Primes/s", prime_count as f64/time_start.elapsed().as_secs_f64());
|
|
|
|
print!(
|
|
|
|
|
|
|
|
"{} Primes/s",
|
|
|
|
|
|
|
|
prime_count as f64 / time_start.elapsed().as_secs_f64()
|
|
|
|
|
|
|
|
);
|
|
|
|
if let Err(e) = buffer.write(&format!("{}\n", prime).into_bytes()) {
|
|
|
|
if let Err(e) = buffer.write(&format!("{}\n", prime).into_bytes()) {
|
|
|
|
panic!(e);
|
|
|
|
panic!(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -48,6 +51,7 @@ fn main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn get_primes(start: u64, incr: u64, tx: &Sender<u64>) {
|
|
|
|
fn get_primes(start: u64, incr: u64, tx: &Sender<u64>) {
|
|
|
|
|
|
|
|
println!("Hi, I'm a thread.");
|
|
|
|
let mut num = start;
|
|
|
|
let mut num = start;
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
let mut is_prime = true;
|
|
|
|
let mut is_prime = true;
|
|
|
@ -55,7 +59,7 @@ fn get_primes(start: u64, incr: u64, tx: &Sender<u64>) {
|
|
|
|
num += incr;
|
|
|
|
num += incr;
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i in (3u64..&num/2).step_by(2) {
|
|
|
|
for i in (3u64..&num / 2).step_by(2) {
|
|
|
|
if num % i == 0 {
|
|
|
|
if num % i == 0 {
|
|
|
|
is_prime = false;
|
|
|
|
is_prime = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|