sapling/eden/mononoke/cmds/benchmark_storage_config/single_puts.rs
Simon Farnsworth e58925a771 Make clippy happier with vec initialization in blobstore benchmark
Summary: It says I was doing it the slow way. Do it the fast way

Reviewed By: krallin

Differential Revision: D20926911

fbshipit-source-id: 65790d510d626e70a402c22a2df5d7606427aa7f
2020-04-13 08:37:59 -07:00

53 lines
1.6 KiB
Rust

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
use std::sync::Arc;
use criterion::{BenchmarkId, Criterion, Throughput};
use futures::compat::Future01CompatExt;
use rand::{thread_rng, Rng, RngCore};
use tokio_compat::runtime::Runtime;
use blobstore::{Blobstore, BlobstoreBytes};
use context::CoreContext;
use crate::{KB, MB};
pub fn benchmark(
c: &mut Criterion,
ctx: CoreContext,
blobstore: Arc<dyn Blobstore>,
runtime: &mut Runtime,
) {
let mut group = c.benchmark_group("single_puts");
for size in [128, 16 * KB, 512 * KB, 8 * MB].iter() {
group.throughput(Throughput::Bytes(*size as u64));
group.bench_with_input(BenchmarkId::from_parameter(size), size, |b, &size| {
let mut block = vec![0; size];
thread_rng().fill(&mut block as &mut [u8]);
let block = BlobstoreBytes::from_bytes(block);
let test = |ctx, blobstore: Arc<dyn Blobstore>| {
let block = block.clone();
async move {
let key = format!("benchmark.{:x}", thread_rng().next_u64());
blobstore
.put(ctx, key, block)
.compat()
.await
.expect("Put failed");
}
};
b.iter(|| {
runtime.block_on_std(async { test(ctx.clone(), Arc::clone(&blobstore)).await })
});
});
}
group.finish();
}