mirror of
https://github.com/facebook/sapling.git
synced 2025-01-07 14:10:42 +03:00
lz4-pyframe: add a benchmark
Summary: This gives some sense about how fast it is. Background: I was trying to get rid of python-lz4, by exposing this to Python. However, I noticed it's 10x slower than python-lz4. Therefore I added some benchmark here to test if it's the wrapper or the Rust lz4 code. It does not seem to be this crate: ``` # Pure Rust compress (100M) 77.170 ms decompress (~100M) 67.043 ms # python-lz4 In [1]: import lz4, os In [2]: b=os.urandom(100000000); In [3]: %timeit lz4.compress(b) 10 loops, best of 3: 87.4 ms per loop ``` Reviewed By: DurhamG Differential Revision: D13516205 fbshipit-source-id: f55f94bbecc3b49667ed12174f7000b1aa29e7c4
This commit is contained in:
parent
b3893b3d3c
commit
35c85018cd
@ -9,4 +9,11 @@ failure = "0"
|
|||||||
lz4-sys = "1"
|
lz4-sys = "1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
minibench = { path = "../minibench" }
|
||||||
quickcheck = "0"
|
quickcheck = "0"
|
||||||
|
rand_chacha = "0.1.0"
|
||||||
|
rand_core = "0.3.0"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "bench"
|
||||||
|
harness = false
|
||||||
|
32
lib/lz4-pyframe/benches/bench.rs
Normal file
32
lib/lz4-pyframe/benches/bench.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// Copyright 2018 Facebook, Inc.
|
||||||
|
//
|
||||||
|
// This software may be used and distributed according to the terms of the
|
||||||
|
// GNU General Public License version 2 or any later version.
|
||||||
|
|
||||||
|
extern crate lz4_pyframe;
|
||||||
|
extern crate minibench;
|
||||||
|
extern crate rand_chacha;
|
||||||
|
extern crate rand_core;
|
||||||
|
|
||||||
|
use lz4_pyframe::{compress, decompress};
|
||||||
|
use minibench::{bench, elapsed};
|
||||||
|
use rand_core::{RngCore, SeedableRng};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut rng = rand_chacha::ChaChaRng::seed_from_u64(0);
|
||||||
|
let mut buf = vec![0u8; 100_000000];
|
||||||
|
rng.fill_bytes(&mut buf);
|
||||||
|
let compressed = compress(&buf).unwrap();
|
||||||
|
|
||||||
|
bench("compress (100M)", || {
|
||||||
|
elapsed(|| {
|
||||||
|
compress(&buf).unwrap();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
bench("decompress (~100M)", || {
|
||||||
|
elapsed(|| {
|
||||||
|
decompress(&compressed).unwrap();
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user