1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-29 10:04:49 +03:00
wezterm/rangeset/benches/rangeset.rs
Wez Furlong 14f0162688 rangeset: fix accidentally quadratic complexity
When adding sparse ranges the cartesian product of range combinations
was explored to find intersections, which is pretty awful if there
are 1 million entries to be inserted.

This commit employs binary search to reduce the complexity, at
the expense of requiring that the internal range array is sorted.
2022-07-24 12:48:02 -07:00

44 lines
1.2 KiB
Rust

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use rangeset::RangeSet;
fn build_contig_rangeset(size: usize) -> RangeSet<usize> {
let mut set = RangeSet::new();
for i in 0..size {
set.add(i);
}
set
}
fn build_sparse_rangeset(size: usize) -> RangeSet<usize> {
let mut set = RangeSet::new();
for i in (0..size).step_by(2) {
set.add(i);
}
set
}
pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Contig 100", |b| {
b.iter(|| black_box(build_contig_rangeset(100)))
});
c.bench_function("Contig 10000", |b| {
b.iter(|| black_box(build_contig_rangeset(10000)))
});
c.bench_function("Contig 1000000", |b| {
b.iter(|| black_box(build_contig_rangeset(1000000)))
});
c.bench_function("Sparse 100", |b| {
b.iter(|| black_box(build_sparse_rangeset(100)))
});
c.bench_function("Sparse 10000", |b| {
b.iter(|| black_box(build_sparse_rangeset(10000)))
});
c.bench_function("Sparse 1000000", |b| {
b.iter(|| black_box(build_sparse_rangeset(1000000)))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);