#![feature(test)]
extern crate test;
use bitvec::prelude::*;
use test::Bencher;
#[bench]
fn bits_seq_u8(b: &mut Bencher) {
b.iter(|| {
bitarr![LocalBits, u8;
0, 1, 0, 1, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 0, 1, 1, 0, 0,
0, 1, 1, 1, 0, 1, 0, 1,
0, 1, 1, 1, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 1, 0, 1, 1, 0, 1,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 1,
]
});
}
#[bench]
fn bits_seq_u16(b: &mut Bencher) {
b.iter(|| {
bitarr![LocalBits, u16;
0, 1, 0, 1, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 0, 1, 1, 0, 0,
0, 1, 1, 1, 0, 1, 0, 1,
0, 1, 1, 1, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 1, 0, 1, 1, 0, 1,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 1,
]
});
}
#[bench]
fn bits_seq_u32(b: &mut Bencher) {
b.iter(|| {
bitarr![LocalBits, u32;
0, 1, 0, 1, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 0, 1, 1, 0, 0,
0, 1, 1, 1, 0, 1, 0, 1,
0, 1, 1, 1, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 1, 0, 1, 1, 0, 1,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 1,
]
});
}
#[bench]
#[cfg(target_pointer_width = "64")]
fn bits_seq_u64(b: &mut Bencher) {
b.iter(|| {
bitarr![LocalBits, u64;
0, 1, 0, 1, 0, 0, 1, 1,
0, 1, 1, 0, 0, 0, 0, 1,
0, 1, 1, 0, 1, 1, 0, 0,
0, 1, 1, 1, 0, 1, 0, 1,
0, 1, 1, 1, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 0, 1, 0, 1, 1, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0,
0, 1, 1, 0, 1, 1, 0, 1,
0, 1, 1, 0, 1, 1, 1, 1,
0, 1, 1, 0, 1, 1, 1, 0,
0, 1, 1, 0, 0, 1, 0, 0,
0, 1, 1, 0, 1, 1, 1, 1,
0, 0, 1, 0, 0, 0, 0, 1,
]
});
}
#[bench]
fn bits_rep_u8(b: &mut Bencher) {
b.iter(|| bitarr![LocalBits, u8; 0; 120]);
b.iter(|| bitarr![LocalBits, u8; 1; 120]);
}
#[bench]
fn bits_rep_u16(b: &mut Bencher) {
b.iter(|| bitarr![LocalBits, u16; 0; 120]);
b.iter(|| bitarr![LocalBits, u16; 1; 120]);
}
#[bench]
fn bits_rep_u32(b: &mut Bencher) {
b.iter(|| bitarr![LocalBits, u32; 0; 120]);
b.iter(|| bitarr![LocalBits, u32; 1; 120]);
}
#[bench]
#[cfg(target_pointer_width = "64")]
fn bits_rep_u64(b: &mut Bencher) {
b.iter(|| bitarr![LocalBits, u64; 0; 120]);
b.iter(|| bitarr![LocalBits, u64; 1; 120]);
}
#[bench]
fn bitvec_rep(b: &mut Bencher) {
b.iter(|| bitvec![0; 16 * 16 * 9]);
b.iter(|| bitvec![1; 16 * 16 * 9]);
}
#[bench]
fn vec_rep(b: &mut Bencher) {
b.iter(|| vec![0u8; 16 * 16 * 9 / 8]);
b.iter(|| vec![-1i8; 16 * 16 * 9 / 8]);
}