-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
192 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,13 @@ authors = ["Stephen Akinyemi <[email protected]>"] | |
|
||
[dependencies] | ||
car-mirror = { path = "../car-mirror", version = "0.1", features = ["test_utils"] } | ||
wnfs-common = "0.1.23" | ||
async-std = { version = "1.11", features = ["attributes"] } | ||
anyhow = "1.0" | ||
|
||
[dev-dependencies] | ||
criterion = { version = "0.4", default-features = false } | ||
|
||
[[bench]] | ||
name = "a_benchmark" | ||
name = "in_memory" | ||
harness = false |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use car_mirror::{ | ||
common::Config, | ||
pull, push, | ||
test_utils::{arb_ipld_dag, links_to_padded_ipld, setup_blockstore}, | ||
}; | ||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; | ||
use wnfs_common::MemoryBlockStore; | ||
|
||
pub fn push(c: &mut Criterion) { | ||
let mut rvg = car_mirror::test_utils::Rvg::deterministic(); | ||
|
||
c.bench_function("push cold", |b| { | ||
b.iter_batched( | ||
|| { | ||
let (blocks, root) = rvg.sample(&arb_ipld_dag( | ||
250..256, | ||
0.9, // Very highly connected | ||
links_to_padded_ipld(10 * 1024), | ||
)); | ||
let store = async_std::task::block_on(setup_blockstore(blocks)).unwrap(); | ||
(store, root) | ||
}, | ||
|(ref client_store, root)| { | ||
let server_store = &MemoryBlockStore::new(); | ||
let config = &Config::default(); | ||
|
||
// Simulate a multi-round protocol run in-memory | ||
async_std::task::block_on(async move { | ||
let mut request = push::request(root, None, config, client_store).await?; | ||
loop { | ||
let response = push::response(root, request, config, server_store).await?; | ||
|
||
if response.indicates_finished() { | ||
break; | ||
} | ||
request = push::request(root, Some(response), config, client_store).await?; | ||
} | ||
|
||
Ok::<(), anyhow::Error>(()) | ||
}) | ||
.unwrap(); | ||
}, | ||
BatchSize::LargeInput, | ||
) | ||
}); | ||
} | ||
|
||
pub fn pull(c: &mut Criterion) { | ||
let mut rvg = car_mirror::test_utils::Rvg::deterministic(); | ||
|
||
c.bench_function("pull cold", |b| { | ||
b.iter_batched( | ||
|| { | ||
let (blocks, root) = rvg.sample(&arb_ipld_dag( | ||
250..256, | ||
0.9, // Very highly connected | ||
links_to_padded_ipld(10 * 1024), // 10KiB random data per block | ||
)); | ||
let store = async_std::task::block_on(setup_blockstore(blocks)).unwrap(); | ||
(store, root) | ||
}, | ||
|(ref server_store, root)| { | ||
let client_store = &MemoryBlockStore::new(); | ||
let config = &Config::default(); | ||
|
||
// Simulate a multi-round protocol run in-memory | ||
async_std::task::block_on(async move { | ||
let mut request = pull::request(root, None, config, client_store).await?; | ||
loop { | ||
let response = pull::response(root, request, config, server_store).await?; | ||
request = pull::request(root, Some(response), config, client_store).await?; | ||
|
||
if request.indicates_finished() { | ||
break; | ||
} | ||
} | ||
|
||
Ok::<(), anyhow::Error>(()) | ||
}) | ||
.unwrap(); | ||
}, | ||
BatchSize::LargeInput, | ||
) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, push, pull); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use anyhow::Result; | ||
use bytes::Bytes; | ||
use libipld::{Cid, Ipld, IpldCodec}; | ||
use libipld_core::codec::Encode; | ||
use wnfs_common::{BlockStore, MemoryBlockStore}; | ||
|
||
/// Take a list of dag-cbor IPLD blocks and store all of them as dag-cbor in a | ||
/// MemoryBlockStore & return it. | ||
pub async fn setup_blockstore(blocks: Vec<(Cid, Ipld)>) -> Result<MemoryBlockStore> { | ||
let store = MemoryBlockStore::new(); | ||
for (cid, ipld) in blocks.into_iter() { | ||
let cid_store = store | ||
.put_block(encode(&ipld), IpldCodec::DagCbor.into()) | ||
.await?; | ||
debug_assert_eq!(cid, cid_store); | ||
} | ||
|
||
Ok(store) | ||
} | ||
|
||
/// Encode some IPLD as dag-cbor. | ||
pub fn encode(ipld: &Ipld) -> Bytes { | ||
let mut vec = Vec::new(); | ||
ipld.encode(IpldCodec::DagCbor, &mut vec).unwrap(); | ||
Bytes::from(vec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.