mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
b1c85aaf4b
Summary: Eventually, we want everything to be `async`/`await`; as a stepping stone in that direction, switch the remaining lobstore traits to new-style futures. This just pushes the `.compat()` out to old-style futures, but it makes the move to non-'static lifetimes easier, as all the compile errors will relate to lifetime issues. Reviewed By: krallin Differential Revision: D22183228 fbshipit-source-id: 3fe3977f4469626f55cbf5636d17fff905039827
54 lines
1.6 KiB
Rust
54 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 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_gets");
|
|
|
|
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 key = format!("benchmark.{:x}", thread_rng().next_u64());
|
|
runtime.block_on_std(async {
|
|
blobstore
|
|
.put(ctx.clone(), key.clone(), block)
|
|
.await
|
|
.expect("Put failed")
|
|
});
|
|
let test = |ctx, blobstore: Arc<dyn Blobstore>| {
|
|
let key = &key;
|
|
async move {
|
|
blobstore.get(ctx, key.clone()).await.expect("Get failed");
|
|
}
|
|
};
|
|
b.iter(|| {
|
|
runtime.block_on_std(async { test(ctx.clone(), Arc::clone(&blobstore)).await })
|
|
});
|
|
});
|
|
}
|
|
group.finish();
|
|
}
|