Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a combinatorial prime number counter #28

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ab19c87
Commit new crate
justAnotherMathmo Oct 15, 2019
d846377
Add raw script
justAnotherMathmo Oct 15, 2019
83a79c7
Better naming convention
justAnotherMathmo Oct 15, 2019
3bf2d94
Get code building
justAnotherMathmo Oct 15, 2019
998c7d8
Clean up code + warnings
justAnotherMathmo Oct 15, 2019
44fce08
Tactical sed
justAnotherMathmo Oct 15, 2019
7d7ff8b
Commit minor textual change to function I'm removing anyway
justAnotherMathmo Oct 15, 2019
c675fe3
Minor textual change
justAnotherMathmo Oct 15, 2019
fc2792f
*sigh*
justAnotherMathmo Oct 15, 2019
4c01281
Improve readability
justAnotherMathmo Oct 16, 2019
3ff61d8
Fix merge conflict
justAnotherMathmo Oct 16, 2019
992c3fc
Remove logging line
justAnotherMathmo Oct 16, 2019
1922499
Whoops, fix merge
justAnotherMathmo Oct 16, 2019
1f7368a
Cleanup and some comments
justAnotherMathmo Oct 17, 2019
7b518cf
More comments
justAnotherMathmo Oct 17, 2019
92c7d76
Add object for multiple calls
justAnotherMathmo Oct 19, 2019
e78d1d5
Add some benchmarks
justAnotherMathmo Oct 19, 2019
0de5956
Update benches and .toml
justAnotherMathmo Oct 19, 2019
9a9d44d
Cleanup and start using primal library
justAnotherMathmo Oct 19, 2019
f76d244
Refactor
justAnotherMathmo Oct 19, 2019
d928a07
Update Cargo.toml
justAnotherMathmo Oct 19, 2019
11bf5c8
Clean up tests
justAnotherMathmo Oct 19, 2019
54c2ea6
Clean up tests
justAnotherMathmo Oct 19, 2019
605a225
Fix bug and update documentation
justAnotherMathmo Oct 19, 2019
7ec5a82
Update global Cargo.toml and lib.rs
justAnotherMathmo Oct 20, 2019
a1a678d
Update benchmarks
justAnotherMathmo Oct 20, 2019
7febca9
Significantly speed up computation of meissel for large values
justAnotherMathmo Oct 20, 2019
5f18d7c
Paranoia bugfix
justAnotherMathmo Oct 20, 2019
bd169f4
Minor improvement
justAnotherMathmo Oct 20, 2019
3dc9830
Unify api
justAnotherMathmo Oct 20, 2019
2a85ef2
Get rid of unneeded line
justAnotherMathmo Oct 20, 2019
8079235
Speed things up by better evaluation of meissel and cache a larger sieve
justAnotherMathmo Oct 30, 2019
405d160
Whitespace
justAnotherMathmo Oct 30, 2019
91a00ff
Rust fmt
justAnotherMathmo Nov 1, 2019
e916985
More cleaning
justAnotherMathmo Nov 1, 2019
6f8eebf
silly me
justAnotherMathmo Nov 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ prime).
primal-check = { path = "primal-check", version = "0.2" }
primal-estimate = { path = "primal-estimate", version = "0.2" }
primal-sieve = { path = "primal-sieve", version = "0.2" }
primal-count = { path = "primal-count", version = "0.1" }

[dev-dependencies]
primal-slowsieve = { path = "primal-slowsieve", version = "0.2" }
Expand All @@ -42,5 +43,6 @@ members = [
"primal-estimate",
"primal-sieve",
"primal-slowsieve",
"primal-count",
"generators",
]
59 changes: 56 additions & 3 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#[macro_use]
extern crate criterion;
extern crate primal;
use criterion::{Criterion, Fun};
use criterion::{Criterion, Fun, ParameterizedBenchmark};

const N: usize = 1_000_000;
const STEP: usize = 101;
const SIZES: [usize; 8] = [100, 10_000, 100_000, 1_000_000, 10_000_000, 100_000_000, 1_000_000_000, 10_000_000_000];

macro_rules! create_benchmarks {
($(
fn $group_id: ident($input: expr) {
$first_name: expr => $first_func: expr,
$($rest_name: expr => $rest_func: expr,)*
}
)*) => {
$(
fn $group_id(c: &mut Criterion) {
let input = $input;

let bench = ParameterizedBenchmark::new(
$first_name, $first_func, input.into_iter().cloned())
$( .with_function($rest_name, $rest_func) )*;
c.bench(stringify!($group_id), bench);
}
)*
}
}

fn is_prime(c: &mut Criterion) {
let miller_rabin = Fun::new(
Expand Down Expand Up @@ -35,6 +56,38 @@ fn is_prime(c: &mut Criterion) {
"is_prime", vec![miller_rabin, sieve, sieve_with_init], ());
}

criterion_group!(benches, is_prime);
criterion_main!(benches);
create_benchmarks!{
fn prime_pi(SIZES) {
"PrimeCounter" => |b, upto: &usize| {
let mut s = primal::PrimeCounter::new(*upto + 1);
b.iter(|| s.prime_pi(*upto));
},
"Sieve" => |b, upto: &usize| {
let s = primal::Sieve::new(*upto + 1);
b.iter(|| s.prime_pi(*upto));
},

"PrimeCounter with init" => |b, upto: &usize| {
b.iter(|| {
let mut s = primal::PrimeCounter::new(*upto + 1);
s.prime_pi(*upto)
});
},
"Sieve with init" => |b, upto: &usize| {
b.iter(|| {
let s = primal::Sieve::new(*upto + 1);
s.prime_pi(*upto)
});
},

"StreamingSieve" => |b, upto: &usize| {
b.iter(|| primal::StreamingSieve::prime_pi(*upto))
},
"Primes" => |b, upto: &usize| {
b.iter(|| primal::Primes::all().take_while(|x| *x <= *upto).count())
},
}
}

criterion_group!(benches, is_prime, prime_pi);
criterion_main!(benches);
26 changes: 26 additions & 0 deletions primal-count/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "primal-count"
version = "0.1.0"
authors = ["Kaimyn Chapman <[email protected]>"]

homepage = "https://github.com/huonw/primal"
repository = "https://github.com/huonw/primal"
documentation = "http://docs.rs/primal-sieve/"
license = "MIT/Apache-2.0"
keywords = ["math", "mathematics", "primes", "number-theory"]

description = """
A combinatorial prime counting library
"""

[dependencies]
primal-sieve = { path = "../primal-sieve", version = "0.2.9" }

[dev-dependencies]
primal = { path = "..", version = "0.2" }
bencher = "0.1.5"
criterion = "0.2"

[[bench]]
name = "bench"
harness = false
58 changes: 58 additions & 0 deletions primal-count/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#[macro_use]
extern crate criterion;
extern crate primal_count;
use criterion::{Criterion, ParameterizedBenchmark};
use primal_count::PrimeCounter;

const SIZES: [usize; 7] = [
100,
10_000,
100_000,
1_000_000,
10_000_000,
10_000_000_000,
100_000_000_000,
];

macro_rules! create_benchmarks {
($(
fn $group_id: ident($input: expr) {
$first_name: expr => $first_func: expr,
$($rest_name: expr => $rest_func: expr,)*
}
)*) => {
$(
fn $group_id(c: &mut Criterion) {
let input = $input;

let bench = ParameterizedBenchmark::new(
$first_name, $first_func, input.into_iter().cloned())
$( .with_function($rest_name, $rest_func) )*;
c.bench(stringify!($group_id), bench);
}
)*
}
}

create_benchmarks! {
fn new(SIZES) {
"PrimeCounter" => |b, upto: &usize| b.iter(|| PrimeCounter::new(*upto)),
}

fn prime_pi(SIZES) {
"PrimeCounter" => |b, upto: &usize| {
let mut s = PrimeCounter::new(*upto + 1);
b.iter(|| s.prime_pi(*upto));
},

"PrimeCounter with init" => |b, upto: &usize| {
b.iter(|| {
let mut s = PrimeCounter::new(*upto + 1);
s.prime_pi(*upto)
});
},
}
}

criterion_group!(benches, new, prime_pi);
criterion_main!(benches);
4 changes: 4 additions & 0 deletions primal-count/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod prime_count;
mod util;
pub use prime_count::PrimeCounter;
pub use util::{int_cubic_root, int_quartic_root, int_square_root};
Loading