sapling/lib/radixbuf/benches/bench.rs
Jun Wu 69a6c18747 indexedlog: normalize benchmarks to use 204800 entries
Summary:
This makes it easier to compare benchmark results between abstractions.

A sample of the result is listed below. Comparing to radixbuf, which is highly
optimized and less flexible, indexedlog is about 10x slower on insertion, and
about 3x slower on lookup.

indexedlog:

  index insertion (owned key)    90.201 ms
  index insertion (referred key) 81.567 ms
  index flush                    50.285 ms
  index lookup (memory)          25.201 ms
  index lookup (disk, no verify) 31.325 ms
  index lookup (disk, verified)  46.893 ms

  log insertion                  18.421 ms
  log insertion (no checksum)    12.106 ms
  log insertion with index      110.143 ms
  log flush                       8.783 ms
  log iteration (memory)          6.444 ms
  log iteration (disk)            6.719 ms

raidxbuf:

  index insertion                11.874 ms
  index lookup                    8.495 ms

Differential Revision: D14635330

fbshipit-source-id: 28b3f33b87f4e882cb3839c37a2a11b8ac80d3e9
2019-03-27 16:29:58 -07:00

54 lines
1.5 KiB
Rust

// 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 minibench;
extern crate radixbuf;
extern crate rand;
use minibench::{bench, elapsed};
use rand::{ChaChaRng, RngCore};
use radixbuf::key::{FixedKey, KeyId};
use radixbuf::radix::{radix_insert, radix_lookup};
const N: usize = 204800;
/// Generate random buffer
fn gen_buf(size: usize) -> Vec<u8> {
let mut buf = vec![0u8; size];
ChaChaRng::new_unseeded().fill_bytes(buf.as_mut());
buf
}
fn batch_insert_radix_buf(key_buf: &Vec<u8>, count: usize) -> Vec<u32> {
let mut radix_buf = vec![0u32; 16];
for i in 0..count {
let key_id: KeyId = ((i * 20) as u32).into();
radix_insert(&mut radix_buf, 0, key_id, FixedKey::read, key_buf).expect("insert");
}
radix_buf
}
fn main() {
bench("index insertion", || {
let key_buf = gen_buf(20 * N);
elapsed(|| {
batch_insert_radix_buf(&key_buf, N);
})
});
bench("index lookup", || {
let key_buf = gen_buf(20 * N);
let radix_buf = batch_insert_radix_buf(&key_buf, N);
elapsed(move || {
for i in 0..N {
let key_id = (i as u32 * 20).into();
let key = FixedKey::read(&key_buf, key_id).unwrap();
radix_lookup(&radix_buf, 0, &key, FixedKey::read, &key_buf).expect("lookup");
}
})
});
}