-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Rushmore Mushambi <[email protected]>
- Loading branch information
1 parent
dc7ff51
commit 5e87d9e
Showing
4 changed files
with
100 additions
and
77 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use bincode::Options; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::random; | ||
use roaring::RoaringTreemap; | ||
use std::time::SystemTime; | ||
|
||
fn bench_roaring_serialization_benchmark() { | ||
let mut val = RoaringTreemap::new(); | ||
for i in 0..50_000_000 { | ||
if random() { | ||
val.insert(i); | ||
} | ||
} | ||
// COLLECTING ELAPSED TIME AND SIZE | ||
|
||
//Bincode with default options is: Slower and bigger than direct serialization | ||
let bincode_elapsed; | ||
let bincode_size; | ||
{ | ||
let mut mem: Vec<u8> = vec![]; | ||
let t = SystemTime::now(); | ||
bincode::serialize_into(&mut mem, &val).unwrap(); | ||
bincode_elapsed = t.elapsed().unwrap(); | ||
bincode_size = mem.len(); | ||
} | ||
//Bincode with options is: As fast, but still bigger than direct serialization | ||
let bincode_options_elapsed; | ||
let bincode_options_size; | ||
{ | ||
let mut mem: Vec<u8> = vec![]; | ||
let t = SystemTime::now(); | ||
bincode::options() | ||
.with_no_limit() | ||
.with_little_endian() | ||
.with_varint_encoding() | ||
.reject_trailing_bytes() | ||
.serialize_into(&mut mem, &val) | ||
.unwrap(); | ||
bincode_options_elapsed = t.elapsed().unwrap(); | ||
bincode_options_size = mem.len(); | ||
} | ||
//Direct serialization is : Faster and smaller | ||
let direct_elapsed; | ||
let direct_size; | ||
{ | ||
let mut mem: Vec<u8> = vec![]; | ||
let t = SystemTime::now(); | ||
val.serialize_into(&mut mem).unwrap(); | ||
direct_elapsed = t.elapsed().unwrap(); | ||
direct_size = mem.len(); | ||
} | ||
|
||
// ASSERTIONS | ||
assert!( | ||
direct_elapsed < bincode_elapsed, | ||
"direct_elapsed({direct_elapsed:?}) < bincode_elapsed({bincode_elapsed:?})" | ||
); | ||
let rate = direct_elapsed.as_micros() as f32 / bincode_options_elapsed.as_micros() as f32; | ||
assert!(rate < 1.1, "rate({rate}) < 1.1"); | ||
// Direct is smaller | ||
assert!( | ||
direct_size < bincode_size, | ||
"direct_size({direct_size}) < bincode_size({bincode_size})" | ||
); | ||
assert!( | ||
direct_size < bincode_options_size, | ||
"direct_size({direct_size}) < bincode_options_size({bincode_options_size})" | ||
); | ||
} | ||
|
||
fn roaring_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("roaring_benchmark"); | ||
group.sample_size(10); | ||
group.bench_function("bench_roaring_serialization_benchmark", |b| { | ||
b.iter(bench_roaring_serialization_benchmark) | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, roaring_benchmark); | ||
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