#![feature(test)] extern crate rand; extern crate sorted_containers; extern crate test; use rand::{Rand, Rng}; use sorted_containers::SortedVec; use test::Bencher; fn sorted_vec_add(size: usize) { let mut rng = rand::thread_rng(); let mut sorted = SortedVec::::new(); for elem in rng.gen_iter().take(size) { sorted.add(elem) } let vec = sorted.into_vec(); } fn vector_add(size: usize) { let mut rng = rand::thread_rng(); let mut vec = Vec::::with_capacity(size); for elem in rng.gen_iter().take(size) { let i = vec.binary_search(&elem).unwrap_or_else(|e| e); vec.insert(i, elem); } } #[bench] fn bench_vector(b: &mut Bencher) { b.iter(|| vector_add::(100000)); } #[bench] fn bench_sorted_vec(b: &mut Bencher) { b.iter(|| sorted_vec_add::(100000)); }