-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: iterators. mod: rethink crate's module structure.
- Loading branch information
Showing
24 changed files
with
1,568 additions
and
799 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[cfg(not(tarpaulin_include))] | ||
#[inline] | ||
pub fn next_ascii_char(c: char, offset: u8) -> Option<char> { | ||
if c.is_ascii() { | ||
let ascii_val = c as u8; | ||
if ascii_val + offset <= u8::MAX { | ||
Some((ascii_val + offset) as char) | ||
} else { | ||
None // Max ASCII value reached | ||
} | ||
} else { | ||
None // Not an ASCII character | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
use kodiak_sets::sequence::Sequence; | ||
|
||
mod helper; | ||
use helper::next_ascii_char; | ||
|
||
fn seq_new_insert_at_last_index(n: usize) { | ||
let mut seq: Sequence<char> = Sequence::new(); | ||
let mut i: usize = 0; | ||
|
||
while i < n { | ||
seq.insert(i, next_ascii_char('A', (i % 10) as u8).unwrap()); | ||
i += 1; | ||
} | ||
} | ||
|
||
fn vew_new_insert_at_last_index(n: usize) { | ||
let mut vec: Vec<char> = Vec::new(); | ||
let mut i: usize = 0; | ||
|
||
while i < n { | ||
vec.insert(i, next_ascii_char('A', (i % 10) as u8).unwrap()); | ||
i += 1; | ||
} | ||
} | ||
|
||
fn seq_with_capacity_insert_at_last_index(n: usize) { | ||
let mut seq: Sequence<char> = Sequence::with_capacity(n); | ||
let mut i: usize = 0; | ||
|
||
while i < n { | ||
seq.insert(i, next_ascii_char('A', (i % 10) as u8).unwrap()); | ||
i += 1; | ||
} | ||
} | ||
|
||
#[allow(unused)] | ||
fn vec_with_capacity_insert_at_last_index(n: usize) { | ||
let mut vec: Vec<char> = Vec::with_capacity(n); | ||
let mut i: usize = 0; | ||
|
||
while i < n { | ||
vec.insert(i, next_ascii_char('A', (i % 10) as u8).unwrap()); | ||
i += 1; | ||
} | ||
} | ||
|
||
fn bench_seq_new_vs_with_capacity(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench_new_vs_with_capacity"); | ||
let n = 1_000_000; | ||
|
||
group.bench_function(format!("seq new - insert {} chars", n).as_str(), |b| b.iter(|| seq_new_insert_at_last_index(black_box(n)))); | ||
group.bench_function(format!("seq with capacity - insert {} chars", n).as_str(), |b| b.iter(|| seq_with_capacity_insert_at_last_index(black_box(n)))); | ||
} | ||
|
||
fn bench_seq_vs_vec_new(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench_seq_vs_vec_new"); | ||
let n = 1_000_000; | ||
|
||
group.bench_function(format!("vec new - insert {} chars", n).as_str(), |b| b.iter(|| vew_new_insert_at_last_index(black_box(n)))); | ||
group.bench_function(format!("seq new - insert {} chars", n).as_str(), |b| b.iter(|| seq_new_insert_at_last_index(black_box(n)))); | ||
} | ||
|
||
criterion_group!(benches, bench_seq_new_vs_with_capacity, bench_seq_vs_vec_new); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
output_format = "verbose" | ||
ploting_backend = "gnuplot" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.