-
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.
feat!: iterators and benchmarks. (#5)
- Loading branch information
Showing
75 changed files
with
15,602 additions
and
704 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,74 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
||
use kodiak_sets::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); |
1 change: 1 addition & 0 deletions
1
.../0.2.0/data/main/bench_new_vs_with_capacity/seq new - insert 1000000 chars/benchmark.cbor
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 @@ | ||
�bid�hgroup_idxbench_new_vs_with_capacitykfunction_idxseq new - insert 1000000 charsivalue_str�jthroughput�mlatest_recordxmeasurement_230819154548.cbor |
Binary file added
BIN
+2.66 KB
...n/bench_new_vs_with_capacity/seq new - insert 1000000 chars/measurement_230819154548.cbor
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...a/main/bench_new_vs_with_capacity/seq with capacity - insert 1000000 chars/benchmark.cbor
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 @@ | ||
�bid�hgroup_idxbench_new_vs_with_capacitykfunction_idx(seq with capacity - insert 1000000 charsivalue_str�jthroughput�mlatest_recordxmeasurement_230819154604.cbor |
Binary file added
BIN
+2.59 KB
...w_vs_with_capacity/seq with capacity - insert 1000000 chars/measurement_230819154604.cbor
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...hmarks/0.2.0/data/main/bench_seq_vs_vec_new/seq new - insert 1000000 chars/benchmark.cbor
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 @@ | ||
�bid�hgroup_idtbench_seq_vs_vec_newkfunction_idxseq new - insert 1000000 charsivalue_str�jthroughput�mlatest_recordxmeasurement_230819154630.cbor |
Binary file added
BIN
+2.57 KB
...ta/main/bench_seq_vs_vec_new/seq new - insert 1000000 chars/measurement_230819154630.cbor
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...hmarks/0.2.0/data/main/bench_seq_vs_vec_new/vec new - insert 1000000 chars/benchmark.cbor
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 @@ | ||
�bid�hgroup_idtbench_seq_vs_vec_newkfunction_idxvec new - insert 1000000 charsivalue_str�jthroughput�mlatest_recordxmeasurement_230819154618.cbor |
Binary file added
BIN
+2.66 KB
...ta/main/bench_seq_vs_vec_new/vec new - insert 1000000 chars/measurement_230819154618.cbor
Binary file not shown.
Oops, something went wrong.