Skip to content

Commit

Permalink
add benchmarks for compression
Browse files Browse the repository at this point in the history
Signed-off-by: qupeng <qupeng@pingcap.com>
  • Loading branch information
hicqu committed Oct 21, 2020
1 parent d477a6d commit cce48a6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ where
output.as_mut_ptr().add(offset + 4),
buffer.len() as i32,
(capacity - offset) as i32,
1, /* acceleration */
4, /* acceleration */
);
assert!(bytes > 0);
copy_nonoverlapping(
Expand Down Expand Up @@ -142,6 +142,7 @@ extern "C" {
#[cfg(test)]
mod tests {
use super::*;
use test::{black_box, Bencher};

#[test]
fn test_basic() {
Expand Down Expand Up @@ -173,4 +174,39 @@ mod tests {
let decoded = decode_blocks(&encoded);
assert_eq!(input, decoded);
}

fn gen_64k_block() -> Vec<u8> {
let data = b"abcdefghigklmnokqrstuvwxyz";
let block_size = 64 * 1024;
let mut block = Vec::with_capacity(block_size);
while block.len() < block_size {
if block_size - block.len() >= data.len() {
block.extend_from_slice(data);
} else {
block.extend_from_slice(&data[..block_size - block.len()]);
}
}
block
}

#[bench]
fn bench_blocks_64k_8(b: &mut Bencher) {
let block = gen_64k_block();
let blocks = vec![block; 8];
b.iter(|| {
black_box(encode_blocks(|| blocks.iter().map(|x| x.as_slice()), 0, 0));
})
}

#[bench]
fn bench_single_block_64k_8(b: &mut Bencher) {
let block = gen_64k_block();
let mut blocks = Vec::with_capacity(64 * 1024 * 8);
for _ in 0..8 {
blocks.extend_from_slice(&block);
}
b.iter(|| {
black_box(encode_block(&blocks, 0, 0));
})
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(shrink_to)]
#![feature(cell_update)]
#![feature(test)]
extern crate test;

use std::sync::atomic::{AtomicUsize, Ordering};

Expand Down

0 comments on commit cce48a6

Please sign in to comment.